This question already has an answer here:
- How to import a jar in Eclipse 7 answers
I use Eclipse (3.4) and my class compiles without warning or errors. My project uses an external jar file.
Where do I need to put this external jar file in order not to get a java.lang.NoClassDefFoundError
when using this class from another project (not in Eclipse)?
I could just extract the jar into the project folder, but that does not feel right.
Edit: this question is not about importing jars in Eclipse, but using them outside of Eclipse.
It doesn't matter too much where you put it, but you need to configure your other non-Eclipse project to put the external jars in its classpath - or use the extensions directory mechanism, if you must. (That's easier, but making it explicit is arguably better.)
put it in your
jre/lib/ext
foldereverything said about the classpath is true, but this is a consistent and sensible place for it to live.
you can find out your jre folder by looking at the JAVA_HOME environment variable on Windows.
Have a jar inside Eclipse, as James Camfield has written.
Then when you build (Ant, Maven, manually) for distribution, ensure the jar file is included with or within your application jar or war or ear or whatever file, and that any startup scripts include it on the classpath using the -classpath command line option for java, as VonC has written.
Don't worry about sticking the jars in the java extensions folder, all this will do is make you forget about it when it comes to sending your code to a third party to use, because they won't have it set up at their end.