Reputation: 1881
I have two eclipse projects, project A and B. Project A is a JavaEE web application run on Tomcat within eclipse. Project B has some standalone application code. I have added Project B as a project dependency to Project A's Build Path and to Tomcat's classpath (as a User Entry).
Both Project A and B have separate copies of apache commons-lang-2.6.jar, which contains the StringUtils class. When I run the Tomcat server, everything starts up fine. When a request occurs, it is handled by a Servlet in Project A (Which imports and uses StringUtils). It then calls code in Project B, which also uses StringUtils. However, the code in Project B gives the following error:
SEVERE: Servlet.service() for servlet [***Servlet] in context with path [/***] threw exception
[Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
Obviously the StringUtils class was loaded for the Servlet to use.
1) Why can't the runtime environment not find/use the StringUtils already loaded to execute Project B code?
2) How do I fix this so dependencies are handled as they should?
Upvotes: 1
Views: 191
Reputation: 20003
The Java Build Path
controls the classpath when compiling, but you need to also configure the deployment using the Deployment Assembly
property page of your Dynamic Web Project
. After all, you might have added an API jar to compile your project that's available as part of the server runtime when you finally deploy it, or as in your case, made use of another project that must be packaged as a jar in your web app's WEB-INF/lib folder to used at runtime.
Deployment Assembly New and Noteworthy mention
Upvotes: 2