6

I have the Java EE app in Netbeans 7.2.1. Trying to deploy it (building ends OK), I get the error in Tomcat log:

Caused by: javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1454)

Looking for code, that causes this error I found the follow:

public Object lookup(String name) throws NamingException {
    return getURLOrDefaultInitCtx(name).lookup(name);
    }

How is this caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Eugene Shmorgun
  • 2,083
  • 12
  • 42
  • 67
  • That will in case of Tomcat happen when you have for some reason dropped arbitrary servletcontainer-specific JARs in webapp's `/WEB-INF/lib` (which is a common starter's mistake to "fix" compilation errors). Did you do that? – BalusC Dec 19 '12 at 19:34
  • I work with ready app, so ii might be. – Eugene Shmorgun Dec 19 '12 at 19:43
  • Uh ok. Please confirm with "Yes" or "No". If you are completely ignorant about the stuff (been thrown in deep hole without being prepared by some sane JSP/Servlet tutorial?), it'd be helpful if you just list the JARs currently present in webapp's `/WEB-INF/lib` folder. One would be able to point out which ones do not belong there at all. – BalusC Dec 19 '12 at 19:44
  • Yes,I've checked. I did it. – Eugene Shmorgun Dec 19 '12 at 19:51
  • Uh ok. Are you implying that your concrete problem is now solved? – BalusC Dec 19 '12 at 19:53
  • You right! Solution is there. – Eugene Shmorgun Dec 19 '12 at 20:01
  • Okay. I've reposted it as an answer so that you can accept it. – BalusC Dec 19 '12 at 20:02

1 Answers1

10

That will in case of Tomcat happen when you have for some reason dropped arbitrary servletcontainer-specific JARs such as jsp-api.jar, servlet-api.jar, catalina.jar, etc in webapp's /WEB-INF/lib. You should remove all servletcontainer-specific JARs from there, they do not belong there. Also, make sure those JARs are not nested within other JARs you have inside WEB-INF/lib.

This is a common starter's mistake in order to "fix" compilation errors on JSP/Servlet libraries which should have been solved differently; namely by configuring the IDE project to be associated with a "Target server" in Netbeans or "Target runtime" in Eclipse. The IDE will then automagically include the server's libraries during compiletime.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you Balusc! I want to report my experience, so it could be useful to others. In my case, eclipse automatic maven resolver included pom dependencies to tomcat, so those automatic one's didn't exactly work with Eclipse tomcat server. – M3rlino Jan 08 '16 at 09:43
  • 2
    Mark the container-provided libraries as `provided` in pom.xml. – BalusC Jan 08 '16 at 09:44