javaherokujndiembedded-tomcat-8webapp-runner

Heroku webapp-runner JNDI naming, resource not available


I have this resource declared in my src/main/webapp/META-INF/context.xml

<Resource name="jdbc/myDB" type="javax.sql.DataSource" auth="Container" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://..." username="..." password="..." />

When I deploy my app to Tomcat 8 it runs fine and the resource is available.
But when I try to run via webapp-runnner (locally or on Heroku) using this command:

java -jar target/dependency/webapp-runner.jar target/*.war --enable-naming

I get this warning and the resource is not available:

WARNING: Failed to register in JMX: javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory]

I tried adding these dependencies to my pom.xml but it makes no difference:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-dbcp2</artifactId>
    <version>2.1.1</version>
</dependency>   
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-dbcp</artifactId>
    <version>7.0.65</version>
</dependency>   

Please advise.


Solution

  • The dbcp2 JAR files need to be place on the classpath of the java command. To do this, you'll need to use the -cp option instead of the -jar option. You command will look like this (assuming the dbcp2 JARs are also in the target/dependency dir):

    java -cp target/dependency/*.jar webapp.runner.launch.Main target/*.war --enable-naming