java reference libraries while copying and importing projects - eclipse

A java project is created and external libraries are added to it while the location of those external jars are within the same project inside a folder which i created.
So when i copy the project to pendrive and import it to another system(say my friends pc's eclipse) the JRE system libraries and reference libraries are not copied along with it and I have to add them manually.
is there a way that those libraries also can be copied, so next time i just copy the project to pendrive and import to another device and start using it rightaway without adding them again?

Don't add them as External JARs, just add them as JARs. Then, set the project's JRE system library using one of the "Execution Environment" values. This will act as a small abstraction and make the reference portable across machines.

Related

.jcp equivalent for eclipse?

for one of my labs I have in my CS2 class at school, JCreator is installed on the school's computers with a 4.x version, I'm more of an eclipse person myself, I even use it at school in place of JCreator, but the file extension .jcp from what I know is a JCreator related file extension. What can I do to make a folder of files compatible with eclipse, which I use at home as well?
Eclipse identifies its projects by using two files namely .classpath and .project. As long as you can export those along with the project files and structure, you should be able to import a project into another eclipse instance.
I am not sure JCreator can create those files for you but I am sure that every eclipse project generates these files.
You can keep the JCreator specific files in the project folder(s), eclipse will ignore all the files that it cannot process/understand. The problem will be how to keep the libraries you are using in sync in both IDE environments as you edit your project.
You might want to re-factor that out to a build management tool like ant/buildr/maven

Eclipse buildpath automatically taking all JARs of a linked directory

This issue is a variation on the one described here: Eclipse buildpath automatically taking all JARs of a internal directory
But instead of any local folder, I'd rather have a linked folder from another project be picked up automatically in the buildpath.
Basically, I have a main project in my workspace that holds directories lib, ext-lib that contain multiple jar files each. These jar files may be upgraded/removed or new ones added every few days.
I also have many other projects in the workspace that relay on the exact same (up-to-date) jars from my main project.
My goal is that as I modify the jars in these two folders in my main project, to have them as linked folders in all other projects and have those linked projects dynamically picked up as part of the buildpath of all those projects.
Any suggestion on how to do that in eclipse would be highly appreciated.
Unfortunately, the "dynamic directory" plugins people mention can not work with "linked" folders :(
Sincerely,
Guy
I would suggest creating a USER LIBRARY in eclipse and then using that in all of your eclipse projects.
Try going into preferences Java -> Build Path -> User Libraries and creating a new user library with all your jars. Then use this everywhere you need these jars.
See this page for more details.
Also, this page explains creating a user library in a bit more detail. There is also a use-case there which seems a bit more aligned to what you had in mind:
6.2.1. Linked Library Project
A useful hybrid strategy is to configure a user library that is also available as a linked folder in your Eclipse workspace. Follow these steps:
1.
Create a simple project in your workspace. Unlike Java projects, a simple project has no Java build path configuration in its properties. Use the command File > New > Project > Simple Project.
2.
Uncheck the option to use a default project location within the workspace folder and enter the path for your \eclipse-contrib\libraries folder (see Figure 6-8).

How to set reference to the folder which contains multiple jar files?

My environment:
Netbean 6.9.1
Glassfish 3.0.1
Windows 7
Goal:
When my coworkers opens the Netbean Project, the library is already referenced without them manually create library, adding jars into it and reference it.
Detail:
I created Netbean project and the project has reference to few jar files in the folder.
Currently whoever opens the project for the first time, they have to manually create library and refer it to the project.
My project location:
C:\Users\masatosan\Desktop\myProject\myApp
My library location:
C:\Users\masatosan\Desktop\myProject\lib\myLib
The myLib folder contains:
some1.jar
some2.jar
some3.jar
I can achieve my goal if I create reference to individual jar file by defining to project.properties file like below: (creating reference to sqljdbc4.jar)
file.reference.sqljdbc4.jar=../lib/sqljdbc4.jar
javac.classpath=\
${libs.restlib_gfv3ee6.classpath}:\
${file.reference.sqljdbc4.jar}:
But my case is different since I have 3 jars in the myLib folder and wanting to reference them all.
Is it possible to reference all jars in myLib folder?
Please let me know if you need more clarification.
I'm sorry, but it doesn't work that way. When you create a project, you have to add the jar files individually.
However, if you put your lib folder under your project, netbeans will refer to them via relative paths. Then when you share the project (lib directory included), netbeans will be able to automatically find the jar files when the next person uses the project. That way you only have to add jar files once.
Short of using a dependency management tool like maven (which Netbeans has good support for), this is really the best solution. It uses a bit more disk space (obviously), but that's never been a huge issue for me.
I figured how so let me share.
Tool --> Library then library window pop up.
Create library called "MyLib" which contains multiple jars.
Add "MyLib" to your project. This change will be written to project.properties file under nbproject folder.
project.properties file indicates the classpath of lib reference you just added.
It should look like something below
javac.classpath=\
${libs.Excella.classpath}:\
${libs.MyLib.classpath}
Now someone else opens the project from different machine and she just needs to do step#1 and #2, which is to create library with same library name i.e. "MyLib"
I think this is what Bill was saying originally but thought it would be helpful to give step by step instructions since I finally figured .... after long time :D

Eclipse configuration: where to put external libs?

I have configured my Eclipse to have a C:\Eclipse\external_libs directory where I place all my external libraries. In my case , my external libs are WATIJ, XMLUNIT, and XOM . Adding the external libs to the project is no problem... there is no question about that.
I also place my JDK at C:\Eclipse\Javasoft .
What I am wondering IS : is there a better location to place external libs? It's important to note that I like being able to pack my Eclipse directory into a zip file and move it and open it on another computer in a portable fashion.
It's normally done on a per app/project basis. For java webapps you normally have your external libs in WEB-INF/lib. However, if you share the libraries across projects AND you need to zip your eclipse directory, what you're doing now is probably the best solution imo.
In linux you could add them to something like /usr/lib/share and include that in your classpath (but you couldn't zip it all up), but not sure if that sort of directory exists in windows.
If you do place all your library in an external folder, please use "linked resources" to avoid putting any fixed path in your .classpath file.
You can then reference that external directory from within your project, with a linked folder.

Dynamic lib(rary) in Eclipse for NON-Dynamic Web Projects

Is there a way to add a dynamic library folder to a plain Java project similar to WEB-INF/lib in a Dynamic Web Project?
I mean, can I specify a simple folder, let's just call it lib, and have Eclipse monitor it for any library jars I might want to add or remove.
Currently I only know this behaviour from the Web App Libraries where any jar you copy into WebContent/WEB-INF/lib is automatically added to the class path, but in "regular" Java Projects I need to add every jar by hand.
Yes and no. It requires writing a suitable extension to the org.eclipse.jdt.core.classpathContainerInitializer. If you're in the Package Explorer, though, you can just select all the jars within the View and use the context menu to add/remove them to/from the Java Build Path.