1

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?

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
freepublicview
  • 716
  • 2
  • 12
  • 25
  • Related: http://stackoverflow.com/questions/4076601/how-do-i-import-the-javax-servlet-api-in-my-eclipse-project/4076706#4076706 – BalusC Nov 09 '11 at 12:37
  • 3
    Everyone's saying you "should" not, but it's actually you *must* not, include the JEE jars in your web app. – Dave Newton Nov 09 '11 at 15:03

2 Answers2

9

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."

Piotr Nowicki
  • 17,914
  • 8
  • 63
  • 82
  • Thanks for your reply. For compilation purpose i had to add them. I couldn't compile without these jars. – freepublicview Nov 09 '11 at 11:33
  • You can add jars which resides in different location than WEB-INF/lib. I.e. if you're using Eclipse you can add 'user library' which defines all container-related libs or you can add 'external jars' and just select those from your tomcat7 directory. – Piotr Nowicki Nov 09 '11 at 11:36
  • 2
    Or 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. – BalusC Nov 09 '11 at 12:51
  • @freepublicview If your satisfied with any answer feel free to accept it, so the question can be marked as answered. – Piotr Nowicki Nov 17 '11 at 22:27
1

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.

Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50