Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat war deployed via IntelliJ IDEA 13 is returning error

I'm getting the following error deploying my first WAR file in IntelliJ. It is a local issue, supposedly, as this is just a WAR file we deploy to test our setup.

All 80 Maven tests are passing, but when I browse to the web app, I get this error:

java.lang.IllegalArgumentException: javax.naming.NameNotFoundException: Name [jdbc/ipam] is not bound in this Context. Unable to find [jdbc].
    com.myapp1.ipam.rest.JaxRsApplication.<init>(JaxRsApplication.java:26)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1104)
    org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:902)
    org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:872)
    org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:964)
    org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:956)
    org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:336)
    org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:315)
    org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
    org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:310)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)

This seems to be where the problem lies:

    public JaxRsApplication() {
    DataSource datasource;
    try {
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup("java:comp/env");
        datasource = (DataSource) envCtx.lookup("jdbc/ipam");
    } catch (NamingException e) {
        throw new IllegalArgumentException(e);
    }
    this.init(new SystemConfiguration(datasource));
}

This is my first time using IntelliJ, and I am new to Java, so I'm not sure what to do here.

Here is context-fragment.xml

<?xml version='1.0' encoding='utf-8'?>
<Context>
    <Resource name="jdbc/ipam"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              auth="Container"
              type="javax.sql.DataSource"
              initialSize="2"
              maxActive="5"
              maxIdle="5"
              minIdle="1"
              maxWait="10000"
              removeAbandoned="true"
              removeAbandonedTimeout="60"
              logAbandoned="true"
              defaultReadOnly="false"
              username="**********"
              password="**********"
              driverClassName="org.postgresql.Driver"
              validationQuery="select 1"
              validationQueryTimeout="5"
              logValidationErrors="true"
              testOnBorrow="true"
              testWhileIdle="true"
              url="jdbc:postgresql://db1host/ipam_dev_table_here"/>
</Context>
like image 690
taco Avatar asked Nov 29 '22 14:11

taco


1 Answers

Make sure that you have setup IntelliJ to deploy the context.xml file when it starts tomcat. You can do this by

  1. Select "Project Structure" from the File menu

  2. From there, select the "Facets" option. Make sure that you have a Web facet configured. If not, add one.

  3. Once the web facet is added, select "Add Application Server specific descriptor..."

  4. Select Tomcat Context Descriptor from the options and click OK.

By default IntelliJ will point to META-INF/context.xml. If this is not the location of your context file, you will need to edit the Path to the file.

like image 107
Kevin Schwerdtfeger Avatar answered Dec 04 '22 12:12

Kevin Schwerdtfeger