Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE Exception: Name java:comp is not bound in this Context

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?

like image 398
Eugene Shmorgun Avatar asked Dec 19 '12 19:12

Eugene Shmorgun


1 Answers

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.

like image 184
BalusC Avatar answered Sep 30 '22 16:09

BalusC