Set Eclipse Build Path Libraries from Project dir - eclipse

I'm using eclipse with svn and when I add some .jar files to my Build Path eclipse add the jar with the full path from the root.
I know for sure that the file will always be in a folder called lib in the same directory as my project:
for example:
~/lib
~/proj
Can I add the file taking my project's directory as a reference? Something like ../lib?
Because, right now, when somebody makes an update the Build Path needs to be changed...
Thanks a lot

under
Window > Preferences > java > Build Path > User Libraries
you can define user libraries, witch you can add to your class path. just say new type in a name (for example MY_EXTERNAL_LIB_FOO) and hit ok. Then select it (simple click) and hit add JAR..., you can then brows your jars and add the ones you want (multi select is possible)
the entry in .classpath will look something like this
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/MY_EXTERNAL_LIB_FOO"/>
this way you can abstract the location for the libs for your projects, they only need to know the name, Eclipse needs to know where the Libs for a name are located.
If you are versioning the libs too within you project then when editing the Build path hit add JARs... and not add External JARs... you will be prompted wi a list of all the project in the actual workspace, choose the onse you have in your project. the entries in .classpath will be relative to your project.
So if you have the following project layout
+ MyProject
+ src
+ lib
some_3rd_party_lib.jar
then the entry in .classpath will look like
<classpathentry kind="lib" path="lib/some_3rd_party_lib.jar"/>

Related

Netbeans to Eclipse migration for Java Projects

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.

Adding external folder jar in to build path

In my RCP plugin application, earlier having a folder at project level "neededJar" in which i have all external jar needed in project build
But now I want to put all jar at a common library say a lib folder in installation directory, at my workspace i added needed jar as project->build path->configure build path->add external jar it works but when I export the plugin project it is not able to resolve dependency.
I also tried to give it as class path variable but it did not work.
My classpath entry is as follow:
<classpathentry kind="var" path="MY_JAR"/>
<classpathentry kind="var" path="MY_JAR/MYClasses.jar"/>
<classpathentry kind="var" path="MY_JAR/jMYlex.jar"/>
<classpathentry kind="var" path="MY_JAR/MYsm.jar"/>
By digging i got to know, not sure about it I am missing some entry in Manifiest.MF and build properties.
Please count what are the steps that i am missing. Please suggest me through process to add external jar in plugin project
update: it is yet not answered well.
You could use a linked folder.
Create a new folder in your workspace, but open the "advanced" tab in the wizard. Chose "Link to alternate location".
Just be careful with references to folders outside your workspace, since they have a tendency to move from time to time :).

Eclipse classpath container - file for defining associated jars

I have a .classpath file with entries such as
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/current-3d"/>
I can then add external user libraries to that container inside eclipse.
But which file is updated once I've done this? I.e. is there a similar xml file that says JAR's x,y + z are associated with the current-3d container?
Right I did actually find the answer, turns out it's the org.eclipse.jdt.core.prefs file, more info here Where/How does Eclipse store user libraries?
And the specific entry for the jars/user libraries is like so
org.eclipse.jdt.core.userLibrary.current-3d=<?xml version\="1.0" encoding\="UTF-8"?>\r\n<userlibrary systemlibrary\="false" version\="1">\r\n\t<archive path\="C\:/Users/pstatham/javacode/master/RunImported/3d/jgl.jar"/>\r\n</userlibrary>\r\n

Maven in eclipse not showing all folders

I am new to Maven and have been trying to get a project working with Eclipse, hibernate,Maven and mysql. I am stuck at the very first step. I have everything configured properly i think and if i create a new Maven project in eclipse it does not show me any folder under src/main or src/test. although if i go back to that folder in the workspace it has a src/main/java
FUrthermore the src/main/resources folder is not created at the time of project creation?
Any clue what the problem maybe or how i can fix it?
Thank you!
For your first problem, when you create a new Maven project the folders that get created depend on the archetype you choose. Assuming you chose quickstart, then it does create (assuming you chose com.example as your package in the wizard and example-project as your artifactId):
And it configures the project so that /src/main/java is in the Build Path. That said, if you are viewing your project in the Package Explorer view, then the packages are shown outside of the folder structure. So, you would see the the com.example.example_project package containing App.java in the build folder /src/main/java and you would see the com.example.example_project package containing AppTest.java in the build folder /src/test/java. These would show up above the libraries which is above non-build folders which is where you see the src folder.
To answer your second question, no, /src/main/resources is not generated assuming you chose the quickstart archetype (this is governed by the quickstart archetype and does the same thing whether generated in eclipse or on the command line).
And third, to fix this (I assume you mean add the resources folder), find the src/java folder (below the libraries), right click and choose New->Folder. Name it resources. Then right click your project, choose Maven->Update Project. This will cause maven eclipse to reconfigure the project according to the Maven configuration which will result in the /src/main/resources being added to the build path. As such, it will get moved above the libraries next to /src/main/java and /src/test/java.

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".