freepublicview
freepublicview

Reputation: 736

Why shouldn't we place tomcat library in our appln libraries

I have a web application running in Tomcat 7. When I place the tomcat default libraries (jsp-api.jar,servlet-api.jar etc.) in my application/WebContent/WEB-INF/lib, it throws an exception : java.lang.IllegalStateException: No org.apache.tomcat.InstanceManager set in ServletContext

When I delete these jars from my lib and and set tomcat lib in build.xml, it works fine. Can anyone explain to me why this happens? Why can't I use tomcat libraries in my lib folder?

Upvotes: 1

Views: 4147

Answers (2)

Piotr Nowicki
Piotr Nowicki

Reputation: 18174

You basically don't want to add Servlet, JSP, EL or any container-related jars into your application WEB-INF/lib folder.

These libraries are to be provided by the container. If you add them explicitly, the deployed application will have a problem (i.e. two same jars into the same classpath).

EDIT: If you need these jars in order for the code to compile than you can add them to your classpath - they don't need to reside in your application's WEB-INF/lib.

I.e. if you're using Eclipse you can add 'user library': Properties -> Java Build Path -> Libraries -> Add Library which will define all container-related libs; you can also Add External JARs and just select those from your tomcat7 directory.

EDIT 2: As BalusC pointed: "you can just reference it as target runtime, then Eclipse will do the magic. See also the related link which I commented on the question. No need to fiddle with user libraries."

Upvotes: 9

Ramesh PVK
Ramesh PVK

Reputation: 15446

You should not bundle j2ee stand jars in your application. They are provided by the application server. In case you want the jars to be available for compilation, put then in your compilation path while building the application. But do not bundle them in the application.

All IDE's provide opation to exculde jars while bundling the application.

Upvotes: 1

Related Questions