How to only include some files on a Eclipse project? - eclipse

I would like to create an Eclipse project from an existing project made with IAR Workbench.
I have a list of files I want to build, but I don't know how I can tell Eclipse to only include some files only.
I've discovered that I can "exclude" a file by clicking on the file then choosing Resource Configuration/Exclude. I've also found that I can place some filters on Resource Filters, but I have found where I can just include some paths such as
${workspace_loc:/${ProjName}/Foo/Bar/foo.c
How is it possible to do this?

I am going to answer my own question: you can't.
What you can do is to list the files on your Git repository and the files that should be excluded from your Eclipse project. Then you make the difference between both list to get the list of file that are on Eclipse.
Then from the .cproject file you can edit the key
<storageModule>
<!-- ... -->
<configuration>
<!-- ... -->
<sourceEntries>
<entry excluding="{{file}}|{{file}}..."
</sourceEntries>
</configuration>
</storageModule>

Related

Mapping maven structures to Eclipse structures, then analyzing with JDT

I'm trying to generate Java unit tests using Eclipse's JDT. Part of that is determining the classpath that pertains to a particular Java class.
I imported a Maven project named jaffa-framework into Eclipse. Jaffa-framework has several Maven modules, including jaffa-api. Each of the submodules has its own pom.xml. I can build jaffa-framework and its submodules with no problem using Maven from within Eclipse (although it will not build using Project -> Build Project).
<project ...
<artifactId>jaffa-framework</artifactId>
...
<profiles>
<profile>
<id>normal</id>
<modules>
<module>jaffa-api</module>
...
</modules>
</profile>
</profiles>
...
</project>
When I import jaffa-framework into Eclipse as a Maven project, I see the following in the UI:
A Java project: jaffa-framework
Two Folders/IPackageFragmentRoots for jaffa-api:
jaffa-api/src/main/java and jaffa-api/src/test/java
One "plain" folder: jaffa-api
This structure looks weird to me. I expected to see something more like:
jaffa-framework
jaffa-api
jaffa-api/src/main/java
jaffa-api/src/test/java
Perhaps I did something wrong while importing? If you have ideas, please let me know.
If I select a Java file within jaffa-api/src/main/java, I can use JDT to navigate to the jaffa-framework project and get its classpath using javaProject.getResolvedClasspath(true); however, what I really need is the classpath for jaffa-api.
The jaffa-api folder contains a pom file, a .project file, and a .classpath file. I don't see an easy way to navigate to it using JDT, and because it is a folder, I don't see how I could obtain the classpath programmatically using JDT.
I'm also wondering why jaffa-api looks like a plain folder, instead of something more project-like. Eclipse must know that it is some kind of subproject, because the folder contains .classpath and .project files.
Please tell me how I can access the classpath information of jaffa-api using JDT, and/or how I can correct my project set up.
There was something screwy about my original project creation. I'm not sure what.
I solved my problem by deleting my jaffa-framework project by right-clicking on it and choosing "Delete" from the menu. I re-imported the project using File -> Open Projects from File System. I'm guessing the key thing to notice here is that the "Search for nested projects" box is checked. After the project was reloaded, both jaffa-framework and jaffa-api appeared as projects.

How do you change a NetBeans project type after it has been created?

I created a project from existing sources as a PHP project in an older version of NetBeans.
I now want to change the project type to an HTML5/CSS project in NetBeans 7.4.
Is there any easy way to change the type of an existing project in NetBeans?
I'm trying to avoid creating a new project from existing sources as I have all my server connection variables already configured.
The project data is stored within the main project directory in a subdirectory named nbproject.
The file project.xml contains the main configuration data for the TYPE of the project. The type and data xml namexspace settings determine the basic project type. Here is a PHP version:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>codex-slp</name>
</data>
</configuration>
</project>
Here is an HTML5 project version:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.clientproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/clientside-project/1">
<name>csa</name>
</data>
</configuration>
</project>
Note the line is different. The HTML 5 project uses the namespace org.netbeans.modules.web.clientproject. The PHP version is at org.netbeans.modules.php.project.
Also of note is the data xmlns entry with HTML5 pointing to the clientside-project directory while PHP points to the php-project directory.
How to change the project? Not easily. Your best bet:
Close out the NetBeans IDE.
Go to the project directory.
Remove (or rename) the nbproject subdirectory.
Open NetBeans.
Create a new HTML5 project from existing sources.
That will switch the project type from PHP to HTML5 and give you the corresponding dialogue boxes.
The reason I decided to take this approach is there are a lot of other things that hang off this namespace specification. The project.properties file, for example, has very different entries for a PHP project, thinks like the PHP version, that do not exist for the HTML5 project. The HTML5 project has new properties that are not present in PHP projects.
There is also an entire private subdirectory that has a plethora of options set in the private.properties file that contains things like the source remote connection for a PHP project that does not exist nor seem to even be SUPPORTED for an HTML5 project.
There are far too many disparities between the two project types to simply hack up the nbproject directory files and hope it works.
IMO your best option is to follow the steps above to recreate the project.
Sadly, it does not appear as though HTML5 project types have matured to the point of the PHP project types with things like supporting remote pull/push of changed files. For this particular project I've reverted back to the PHP project type even though this is not really a PHP project. I heavily rely upon the automatic remote server push via FTP. How did I restore the project? I renamed my nbproject directory to saved_nbproject, so to revert:
Close Netbeans.
Go to project directory.
Rename my saved_nbproject directory back to nbproject.
Restart NetBeans.
Maybe changing project types AND HTML5 remote server support will be available in the future. For now, with NetBeans 7.4 it does not appear this transition is readily available.
If anyone else has input or other feedback I'd love to hear it as NetBeans has become my go-to tool for complex code projects.
NOTE: I would strongly suggest to create a new project from existing sources to ensure everything will work as expected. In most cases its faster and less problematic.
(If you persist....)
Following the accepted answer may result in an error. Besides what Charleston Software Associates posted, you may need to copy other variables included in "project.properties" file.
For example, these are for PHP: (adjust properly. I suggest to see some of your other projects to prevent mistakes).
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_create_2e_tests=false
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_path=
auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_path=
auxiliary.org-netbeans-modules-php-phpunit.customSuite_2e_path=
auxiliary.org-netbeans-modules-php-phpunit.test_2e_run_2e_all=false
ignore.path=
include.path=
php.version=PHP_53
source.encoding=UTF-8
src.dir=/var/www/example
tags.asp=false
tags.short=false
web.root=.
These are for HTML5:
auxiliary.org-netbeans-modules-css-prep.less_2e_compiler_2e_options=
auxiliary.org-netbeans-modules-css-prep.less_2e_enabled=false
auxiliary.org-netbeans-modules-css-prep.less_2e_mappings=/less:/css
auxiliary.org-netbeans-modules-css-prep.sass_2e_compiler_2e_options=--style compressed
auxiliary.org-netbeans-modules-css-prep.sass_2e_configured=true
auxiliary.org-netbeans-modules-css-prep.sass_2e_enabled=true
auxiliary.org-netbeans-modules-css-prep.sass_2e_mappings=/scss:/css
auxiliary.org-netbeans-modules-javascript2-requirejs.enabled=true
auxiliary.org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder=js
config.folder=${file.reference.example-config}
file.reference.example-config=config
file.reference.example-test=test
file.reference.www-example=/var/www/example
files.encoding=UTF-8
site.root.folder=${file.reference.www-example}
test.folder=${file.reference.example-test}
You can mix both in a single file without any problem.
Using: Netbeans 8.0.1
Try to edit your project.xml replace type with
<type>org.netbeans.modules.web.clientproject</type>
Guys this has changed for version 7.4?
in private.properties
remote.connection=remotename
remote.directory=/public_html/
remote.upload=ON_SAVE
run.as=REMOTE
url=http://remotename.com
I tried changing xml and that didn't work well for me. I fiddled around and found a way that seems simpler to me - just delete and create a new project!
Right click the project in netbeans, and click delete. (make sure to NOT check the box that says delete sources!). That clears out the netbeans project info. Then just make a new project of whatever type you want. Go to File->New Project. Select project type (in this case HTML5 Project with existing sources), making sure to select the one that has "with existing sources". Hit next. Now here is a key part. The site root is your mysite/public_html folder most likely. The project directory is your mysite folder. The netbeans config will be put in the mysite folder.
Then you should be good to go!
Close Netbeans.
Delete nbproject folder inside your app folder. It can be hidden folder , so , in windows, go to folder properties and activate hidden folder.
Reopen Net Beans. Create a new project of the correct type.

Eclipse doesn't find source attachements

When opening a class included through a Maven dependency, Eclipse tells me that the containing .jar file has got no source attachment.
But in the directory in which the .jar file resides, there is also as corresponding -sources.jar file.
Do you have any hints regarding the solution of this problem?
Is there a way to tell Eclipse where it should automatically look for the source attachment?
Edit: In the Eclipse .classpath file, the sourcepath value is set for external archives, but not for ours. But both jars and sources file reside in the same repo.
The property -Declipse.useProjectReferences=false is also set.
The problem was that there were already sources.jar-not-available files for certain projects in my local repository.
I've deleted them and now the attachment of source files is working. Obviously Eclipse respectively the Maven Eclipse plugin doesn't look for source attachments as long as these marker files exist.
If it hadn't been for the comment from K. Claszen I'd have never came up with this solution.
Check that you have downloadSources in the maven-eclipse-plugin section of your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
...
</configuration>
</plugin>
If you are using m2eclipse plugin for integrating Maven projects in Eclipse, you might need to enable downloading sources and javadocs in m2eclipse preferences:
Window > Preferences > Maven > Download Artifact Sources
For me the file was in place in local repo and eclipse (4.5) kept complaining there is no associated source jar (sources.jar-not-available did not existed). I ended up removing the directory from local repo, letting eclipse to download the sources again repolulating the repo, running mvn eclipse:eclipse and refreshing the project.
For me all these steps was necessary to get this working.
For those who are still having trouble downloading sources for your Maven dependencies (like me), you can try this alternate method:
Find the particular Maven dependency you wished to inspect Java source code for. You need to have the Maven artifact name.
Next, navigate to the Maven repository server where you download the Maven dependency from. For example, I have spring-security-core-5.5.1.jar as my Maven dependency. The repository host site is from mvnrepository.com, in which the repository server is from https://repo1.maven.org/maven2/.
Navigate to mvnrepository.com and search for your Maven dependency artifact. In my case, it would be spring-security-core, and I located the artifact information page here.
On this page, in the table row labeled Files, you want to click on View All, on the right of the JAR link with how many kilobytes displayed to the side. (Underlined)
Once you're viewing the list of all JARs provided with the Maven dependency, click and download the one that says, [artifact name]-[artifact version]-sources.jar. In my case, it's spring-security-core-5.5.1-sources.jar.
Once downloaded, on your local machine, use your File Explorer to navigate to the folder containing the artifact JAR which you have trouble downloading the source codes for. In my case, it would be $MAVEN_HOME/repository/org/springframework/security/spring-security-core/5.5.1.
Move the [artifact name]-[artifact version]-sources.jar into this folder.
Go back into Eclipse, and try attaching the sources. You should be able to pick up the ...-sources.jar file upon attaching it.
After attaching it, you will then be able to see the source codes for your Maven dependency.
Right click at project, select Maven, select Download Sources.
I download a maven project from online,use mvn eclipse:eclipse converted to eclipse project then I occurred the problem.
solution is remove all external lib that start with 'M2_REPO',it's work for me.

How to include a resource file in the Jar file generated by Netbeans?

I'm using NB6.7 to auto generate an executable jar file for my project, how and where to tell NB to include a certain resource into the result jar file ? I know if I put the resource in the "lib" directory, NB will put it into "dist/lib/", but what I want is to include the resource within the final executable jar, where in NB do I specify that ?
Frank
There is a way to add arbitrary file/folders to arbitrary location within the jar, without setting up source folders.
NetBeans will, by default, create build.xml at project root.
We can override the -pre-jar target to copy the files and -post-jar target to cleanup.
For example, to copy "res/resource.ext" into "myres/resource.ext" within the jar, add these target to build.xml:
<target name="-pre-jar">
<!-- Single file -->
<copy file="res/resoure.ext" todir="${build.dir}/classes/myres" />
<!-- Folder(s) -->
<copy todir="${build.dir}/classes/myres"><fileset dir="res"/></copy>
</target>
<target name="-post-jar">
<delete dir="${build.dir}/classes/myres/resource.ext" />
<delete dir="${build.dir}/classes/myres"/>
</target>
Since this is Ant, you have great control.
You can rename file, replace file content (e.g. update version or timestamp), convert charset, or run other operations that is not possible with simple inclusion.
I am using NetBeans version 8, but as long as the project is compatible it is likely to work.
Alternatively, use an automated project such as Maven or Gradle, that gives you even more control on the build process, at cost of IDE features such as automatic single file recompile.
I got it : put the resource file in the src dir.
you can do it by...
Go to your project name which is normally on the left hand side of the screen.
Whatever your project name is,
you have to right click on it and then go to the properties of that. [which is normally at the end in menu item]
Then one window will open in that go to the Libraries.
In that you will find
1)ADD PROJECT
2)ADD Libraries
3)ADD JAR FILE
then include the jar / Libraries / folder.
so that will add automatically to your project.
Which will include in lib folder automatically so you don't have to include always.
Hope this help you,

Eclipse 3.4 GWT 1.6 project - how to reference source from other projects?

I've got a GWT 1.6 project in Eclipse 3.4 and am trying to reference source from another (non-GWT) project in my workspace. I've added the project to my build path, but I can't run the application in hosted mode. When I do, I get a "no source code is available" error.
I've done some searching and reading and have tried a few things that others have suggested (including creating a jar from the dependent project and linking to it), but frankly nothing has worked.
If you're actually doing this, could you please help me out with a simple step-by-step setup? I'd really appreciate it, thanks!
I have 2 Eclipse Projects. One is gwt project and one is not. Here's the directory structure that works for me:
workspace
-- gwt-project
-- src/main/java
-- com.gwt.GwtProjectModule
-- GwtProjectModule.gwt.xml
-- non-gwt-project
-- src/main/java
-- com.nongwt.package.that.contains.source.you.need
-- nongwt.gwt.xml
-- com.nongwt.package.that.contains.source.you.need.client
nongwt.gwt.xml tells gwt to look inside "client" package, here's what it looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='nongwt'>
<inherits name='com.google.gwt.user.User' />
<source path="client" />
</module>
GwtProjectModule.gwt.xml can then inherit source code from nongwt. Here's the relevant line from inside GwtProjectModule.gwt.xml:
<inherits name="com.nongwt.package.that.contains.source.you.need.nongwt" />
Make sure you include non-gwt-project inside gwt-project's classpath in eclipse. It's the normal drill; right click on gwt-project, choose properties, choose "Java Build Path", click "Projects" tab, and "non-gwt-project"
Or, instead of including non-gwt-project in gwt-project's classpath as a project reference, you can also jar the contents of non-gwt--project, ensure that you include the source in the jar, and then include the jar in gwt-project's classpath.
Good Luck!
I know this post is quite old but as I spent quite a lot of time on this issue and finally found the way to do it, I thought I might share the answer :
once you've created your launch configuration, open it run>run configurations...
go to classpath tab and select user entries. add advanced>folder and select the source folder of your other module project. If as me you've separated the module conf file in a src/main/resources folder you have to add it as well.
should work.
The client-side code in your GWT project (the classes under the client package) can't reference any classes that aren't in a GWT module.
If you've got code in another project that you want to reference from client code in your GWT project, you need to:
Make sure it's all "GWT safe", which means it doesn't reference any JRE classes that aren't emulated by GWT (http://code.google.com/webtoolkit/doc/1.6/RefJreEmulation.html), or reference any classes that reference JRE classes not emulated
Make sure all referenced classes are within a GWT module. This means putting a MyOtherProject.gwt.xml file in your other project, and all the referenced classes must be under a client subpackage
Make your GWT project inherit from the other project. So add the following to your GWT project's gwt.xml module file:
<inherits name='com.yourCompany.otherProject.MyOtherProject' />
Boden: add the following to your module file
<source path=""></source>
in addition to your other sources, eg:
<source path=""></source>
<source path="com.acme.otherpackage"></source>
then the compiler won't complain.
Atleast that's how I solved it. Not sure if using path="" allows inclusion of everything, I'm assuming it's the default value when no sources are specified.
This is a fantastic solution of your problem proposed by Sven Buschbeck (must a norwegian, lol!), worked for me!
When work­ing on sev­eral large scale projects (in Eclipse), it’s con­ve­nient and of course more effi­cient to share and reuse code via com­mon libraries. While those are in an early stage they need to be changed a lot and there­fore it’s handy to link projects in instead of cre­at­ing new jars each time the library has been updated.
Unfor­tu­nately, this stan­dard approach for Java devel­op­ment in Eclipse does not work that straight for­ward as with plain old Java projects, it requires three steps in total:
Link the library project to all rel­e­vant projects (“Project
Pref­er­ences” -> “Java Build Path” -> “Projects” -> “Add…”)
Then, add the client-side code of the library (by adding it as a
mod­ule.) There­fore, edit the gwt.xml of your appli­ca­tion and add
for exam­ple
where Super­Lib is the file name of the gwt.xml file in you library
project and before that is the pack­age it lies in.
Add the code to the project by link­ing a source folder.
Unfor­tu­nately, this is required if you do not want to write an Ant
script to com­pile your appli­ca­tion. (If you pre­fer Ant check
this out) I don’t like the idea of using such a script because if
you for­get to run it each time you make changes, you will end up in
confusion—let’s go for the con­ve­nient, auto­matic way then.
Add a folder to your appli­ca­tion project; open the “advanced” sec­tion in the folder cre­ation dia­log, select “Link to alter­nate loca­tion” and pick the source folder (usu­ally “src”) of your library project. (Hint: if you work within a team using a ver­sion­ing sys­tem, you can cre­ate a vari­able for that folder and use this instead. This way, each of your col­leagues can put the library project in a dif­fer­ent folder and accom­mo­date for that by adjust­ing the vari­able :) )
Right click the folder, “Build Path” -> “Use as Source Folder”. Done.
Sur­pris­ingly, the GWT plu­gin for Eclipse does not honor the project link­ing, thus all the ref­er­ences need to be made explicit or you will end up with lots of the fol­low­ing: ClassNotFoundException.
GWT doesn't know about that other code because it is not in the client directory of your project. You need to add the source path for the other code to the .gwt.xml file. Just added it to the xml as follows
<source path="common" />
common is the directory where the extra code is for this example.
Check out the XML Element Reference section of this doc
In your gwt project, go to properties, Java build path, source, click "link source" and point to your non-gwt project source package that you wish to include.
Edit: Found a eclipse fix. Run config > Classpath > Advanced > Add folder > otherproject/src .
Reason: Eclipse adds the bin folders of exported projects. GWT needs the src folders.
Elaborating on my comment.
I am using gwt 2.8 on Eclipse Neon, Java 1.8.0_92. Referring to another project in eclipse fails to launch devmode, because it cannot find the source for referred files from the other project.
What worked:
Switched to 'ant devmode' completely. Made the following changes to build.xml:
<target name="gwtc" ...>
<java ...>
<classpath>
<pathelement location="src"/>
<pathelement location="../otherproject/src"/><!-- Added -->
...
...
<target name="devmode" ...>
<java ...>
<classpath>
<pathelement location="src"/>
<pathelement location="../otherproject/src"/><!-- Added -->
Now do a production build with 'ant' or start devmode with 'ant devmode'.
Other things I noticed
Using the method in the accepted answer, otherproject/src/foo.gwt.xml is picked up (complains if not available), and static values from classes are picked up. Nothing else is. Very weird.
I understand that the DevMode/gwtc executables pick up sources from their class path. So all that is needed is for eclipse to add referred projects to their class path. I was not able to achieve this but this seems possible. FIXED see top.