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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With