Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put the external jars? [duplicate]

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.

like image 304
Burkhard Avatar asked Nov 28 '08 11:11

Burkhard


People also ask

Where do I put external JARs module path or class path?

If you've modularized a JAR file but, for some reason, are not ready to have your application treat it as a module yet; you can put it in the class path, and it will work as it always has. The module path is where the named and automatic modules are loaded to work in the Java module system.

What is the location of any external JARs used in an application to store in any war file?

The right place to put a JAR file to make its contents available to a Java web application at runtime is in the WEB-INF\lib directory of the WAR file in which the application is packaged.


1 Answers

If you're wanting to include a JAR file to your Eclipse project, you would generally create a 'lib' folder inside the project folder, and put the file in there. You then need to tell eclipse to include it in your class path so your code will compile and run inside eclipse.

To do that:
- Go into the properties of your project
- Select 'Java Build Path' in the left hand column
- Select the 'Libraries' tab in the centre part of the window
- Click the Add JARs button - this will give you a list of your projects in eclipse - expand your project and into the lib folder - your jar will be there.
- Select the JAR, click OK, and OK again out of the properties window.

Your code will now compile and run.

like image 109
James Camfield Avatar answered Sep 20 '22 15:09

James Camfield