Netbeans to Eclipse migration for Java Projects - eclipse

I currently switched to eclipse and trying to migrate my projects. I created a java-workspace and used 'File->Open Projects from File System'.
The project with all the folders is added, not only the 'src' but everything I put into it (datasheets, documentation,...). Also the libraries are added two times. One time in the folder and what seems like a link to the compiled library.
folder structure
In netbeans I just added the desired library to the /libs folder and linked it to the project.
Can I manually add folders and/ or libraries to existing projects? Why are there two instances of the libraries?

By using Open Projects from File System, folders containing .java files has been configured as source folders (source code intended to be compiled). This can be undone via right-click Build Path > Remove from Build Path (the reverse function is Build Path > Use as Source Folder).
In the Package Explorer, source folders are shown as virtual folders. If the source folder is not a subfolder of the project, it is displayed as virtual folder in addition to the project subfolder to be able to navigate to that non-source project subfolder (in your case you have a single src source folder and in addition to the non-source folder lib you have multiple virtual lib/... source folders).
The node Referenced Libraries lists all JARs and class folders on the Java Build Path (classpath/modulepath). To remove something from the Build Path, right-click it and choose Build Path > Remove from Build Path. JARs can be added to the Build Path by right-clicking the JAR and choosing Build Path > Add to Build Path. Class folders can be added only via Project > Properties: Java Build Path in the tab Libraries with the button Add Class Folder....

I dont know if this is a workaround or good practice for migration:
Create a new Java-Project in Eclipse
add desired Folder structure (including /libs)
In 'Project->Properties -- Libraries' add libraries manually
Clean and Build Project
I have to test functionality and stability but it seems ok.

Related

How to add a library to eclipse of .jar files that are NOT a "User Library"?

I am attempting to add a group of .jar files to my build path for a project that is under source control. Specifically I have downloaded the Smack API and I have a folder located in my project/libs/ that contains the multiple smack .jar files I will need.
If I go to Project > Properties... and try to use "Add Library..." under the "Libraries" tab. The only option that makes sense is to add an "User Library". However, this doesn't work with source control as User Libraries appear to be defined in the workspace/.metadata/ folder, and is not under source control.
I can add each .jar file using Project > Properties... using "Add JARs..." under the "Libraries" tab, but then each .jar shows up separately in the build path (not grouped neatly together like other system libraries). Between HAPI, HTTP Components, and Smack .jar's I need, the build path contains a lot of separate jar files and I just want to group them together.
Is this a limitation of Eclipse? Or am I missing something?
Here's the link from one of my Eclipse projects. Eclipse does not group them together - you just add each jar and get the list from this screen. To add libs that are in the project folder structure, use Add Jars..., for external jars, use Add External Jars...
As mentioned by #mikemil, add external jar is the way for non-web apps.
If your project is a web application and has a .../WEB-INF directory, you can put the jar in the .../WEB-INF/lib directory and it will be in the deployed WAR file as well as in the build path.

How to create .classpath and .project files to make a project compatible with Eclipse Helios?

I am having a Java Web project with some class files, JSP files along with WEB-INF and META-INF folders. I want to use this project in Eclipse Helios.
For this I will need to import this project. However, Eclipse will search for .classpath and .project files in the root directory of the project. And unfortunately, I don't have these.
So, can I create one from the project?
Or do I just have to create one project and copy the files into the project? Though this will be a little tedious task if I have too many packages and class files.
Or do I just have to create one project and copy the files into the
project? Though this will be a little tedious task if I have too many
packages and class files.
It isn't tedious. Just create a blank Dynamic Web Project in Eclipse and copy the source folder. You can add a "Source Folder" to point to where your Java source files are present. It will then automatically add all the packages under it.

Netbeans/Java: reference a jar but not deploy it

I want to build a jar containing a class which I have derived from a class in second jar. I add a reference to the second jar in my project but then Netbeans copies that jar to dist/lib which I don't really want. Is there a way to reference the second jar at compile time but not have it copied.
Specifically, I am making a custom task for Ant so I derive from org.apache.tools.ant.Task and I don't want ant.jar copied to dist/lib.
This is with Netbeans 7.0.
One way of achieving this is to 'Uncheck' the Copy Dependent Libraries check box, which will ensure that no JAR files are copied to dist folder.
Exact Steps:
Right click on the project name and choose Properties option from the context menu, this will open the Project Properties dialog box.
Select the Build > Packaging node from the Categories tree view and uncheck the Copy Dependent Libraries check box
Now build the project and check that no JAR files for libraries are copied to dist folder.

Using java library in eclipse

I'm a bit new to eclipse and want to use the following libraries so that I can use their implemented objects (HttpClient and Java csv). How do I import these libraries so that I can write some java with them?
http://hc.apache.org/downloads.cgi
http://sourceforge.net/projects/javacsv/
What you're looking to do is add the libraries to your project's build path (the class path that will be used while compiling). In Eclipse, you can do this by right-clicking your project and choosing Properties (or hitting [Alt]+[Enter] when the project is selected in Project Explorer, Navigator or Package Explorer views) and then Java Build Path from the sidebar and the Libraries tab where you can add JARs.
Note the difference between Add JARs and External JARs is that External JARs will add an external dependency in your project since the absolute path to the JAR on your filesystem will be put into your project's configuration. With Add JARs you can select JARs from within your workspace.
I find it to be a good practice to create a lib folder (at the same level as my src folder) and put all my JARs in there and then add them to the build path with the Add JARs option. This makes the project portable since there are only relative paths referring to resources within the project rather than absolute paths or resources from other workspace projects.
You add the .jar files you want to use in your projects build path. You access this windows by right-clicking your project. Choosing "Build path" -> "Configure build path".

eclipse, export multiple projects (using a shared binary directory) in one runnable jar

I have three projects which are build to the same /bin directory and anoher projects (let's call it A) where this is not necessary. A requires all the other projects. When I export A as a runnable JAR, then only one of the three projects makes it into the JAR.
I can add other projects (build to different directories) which are copied into the JAR. When I remove the (alphabetic) first of the three project's from the buildpath then the next is included.
Has somebody an idea how to let eclipse copy ALL projects in the JAR without giving up that the three projects are build to the same /bin directory?
Each Eclipse project should have their own bin/ directory; otherwise you will get strange errors. To solve your problem, open the project properties and add the other three projects to A in "Build Path" -> "Projects".
Eclipse will then merge the classpaths of all projects.
To export all the classes in a single JAR file, simply select the source folders of all projects in the JAR exporter.
A workaround would be to create a JAR from each project and include these into A.