Reputation: 545
I'm running Eclipse Indigo 3.7, Tomcat7, Spring MVC framework 2.5.6.
In one of my application project, I have this error message:
nov. 22, 2011 9:06:30 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
Infos: validateJarFile(/home/pc/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SpringMVC/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
I have read that for web application project like mine, servlet-api.jar should not be included in the project build path; Is that right? Where should I put then servlet-api.jar because I've servlet in my application?
Also I would like to ask:
I'm reading often to put jar files in WEB-INF/lib folder, sometimes I'm reading to include them in the project build path as external Jar, sometimes I'm reading to do both at the sametime.
For example, I've read that: -servlet-api.jar is already in Tomcat7/lib directory but need also to be included in the project path; -MySQL JDBC driver for java has to be included in the project path, and copied also in the WEB-INF/lib and Tomcat7/lib directories.
Can anyone tells me the thruth and help me to understand really how to manage «Jar librairies» in a project in eclipse?
Thank you very much.
Upvotes: 1
Views: 5603
Reputation: 56
The tomcat lib directory is a common location for libraries that are used internally by tomcat and available to all applications deployed on that instance of tomcat. You would expect to find the servlet-api.jar here as its all part of what makes tomcat a servlet engine. You can find a more detailed explanation of the tomcat classloader stuff here:
http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
The /WEB-INF/lib
folder of your project contains libraries that are private to only your web application and not visible to any other deployed app on tomcat. Here you would expect to put libraries for the technologies you are using to build your web app, such as Spring, JUnit and maybe Hibernate.
Update:
In terms of managing your libraries with Eclipse, I would strongly advise that you utilize a build system (if you aren't already) such as ANT or Maven.
With Maven you can set up a project in Eclipse by using a web-app archetype and your project's libraries depedencies can be fairly simply managed via your project POM file.
ANT can involve a little more 'heavy lifting' on your part when it comes to manually managing your WEB-INF/lib
directory but you can also use Apache Ivy to help with this.
A quick Google search will reveal many, many tutorials on using these tools.
Hope this helps.
Upvotes: 2
Reputation: 8320
I have read that for web application project like mine, servlet-api.jar should not be included in the project build path; Is that right? Where should I put then servlet-api.jar because I've servlet in my application?
Servlet containers (such as Tomcat)have the servlet JARs in the classpath. So your application WAR should exclude it.
I'm reading often to put jar files in WEB-INF/lib folder, sometimes I'm reading to include them in the project build path as external Jar, sometimes I'm reading to do both at the sametime.
JARs referenced by your application are typically placed in
WEB-INF/lib
. Exceptions are things likeservlet.jar
. You will need them at compile time but will have to exclude them from the resulting WAR.
I've read that: -servlet-api.jar is already in Tomcat7/lib directory but need also to be included in the project path; -MySQL JDBC driver for java has to be included in the project path, and copied also in the WEB-INF/lib and Tomcat7/lib directories.
That is correct. To amplify the answer to previous question, you need these JARs are compile time so that you can compile. Some JARs -- like the
servlet-api
are provided by the servlet container.
Can anyone tells me the thruth and help me to understand really how to manage «Jar librairies» in a project in eclipse?
Build tools such as Maven help manage your project's external library dependencies with fine-grained control over when these dependencies are needed (compile time only, compile and test, at runtime, etc).
Upvotes: 3