ufk
ufk

Reputation: 32134

eclipse helios: tomcat project - jar will not be exported or published. runtime ClassNotFoundExceptions may result

I'm using Eclipse Helios and I was wondering how can I add a library project to my folder that will be copied to the build directory where my compiled project resides.

currently I did the following:

  1. created a lib directory in the root of my project
  2. copied the relevant jars to that dir
  3. My Project -> properties -> Java Build Path -> add jars and I added all the jars from that directory.

after adding all the jars i got the following warning regarding each of the jar file:

jar will not be exported or published. runtime ClassNotFoundExceptions may result

first of all how can I add the directory of the jars instead of individual jars? and the 2nd question is how can I do that the libraries will be deployed properly when compiling my application ?!

Upvotes: 6

Views: 20470

Answers (3)

VonC
VonC

Reputation: 1328212

It can be about:

Can you switch to the navigator view, right-click refresh the project, make sure it's not in the LIB dir,
Then try and drag and drop the JAR into the lib dir and see if it shows up.

When you have total control of you web container/app server, deploying jar files is as easy as dropping the folder in your common lib folder.
If you don't package your web apps as a war file then it's even easier because you only have to drop the jars in the WEB-INF/lib folder of your webapp.
But if you don't have total control of your web server or application server, your only choice is to package the jars you've used with your war file.

While developing a web project using my recently developed utility(a jar file), I encountered a NoClassDefFound error. Of course, it's pretty obvious that the jar file I've made and using on my web project could not be found (not visible in the CLASSPATH).
Adding the jar to the build path only eliminated the compilation problem. Dragging the jar file into the lib folder of my Eclipse workspace isn't a very good idea.
It took me a couple of hours before I figured out the solution:

  1. Right Click on your web project
  2. Click Properties
  3. Select J2EE Module Dependencies
  4. Click the Web Libraries Tab
  5. Add external jars (if the jar is outside of your project). An entry will be added under Jar/Module, make sure you click on the checkbox (checked).

And everything should be fine. I tried exporting to a war file and then checked the content and my jar files are indeed deployed with the war.

  • a project configuration issue

The OP ufk mentions in the comment:

I resolved the issue by:

  • adding a "Web App Libraries" library in "java build path" and
  • adding all the relevant jars into WebContent/WEB-INF/lib

Upvotes: 5

REDA
REDA

Reputation: 483

I was facing the same problem, like whenever I export my web app as a war file, the external added jar files didn't get included in app/lib directory, causing exceptions during deployment.

you Have to switch the navigator view, right-click refresh the project, make sure it's not in the LIB dir (but in the project folder)

then try and drag and drop the JAR into the lib dir and see if it shows up.

Upvotes: 0

ozma
ozma

Reputation: 1803

In eclipse Junu:

in a web project, after adding jar to build path, one must add it to

Deployment Assembly

(in project properties)

when adding that jar to "Deployment Assembly" press the add button and select

Java Build Path Entry

(and not other workspace or file system option)

Upvotes: 10

Related Questions