2
votes

I have a webapp project (in J2EE) that uses Spring and maven. Usually I run this project in my Eclipse tomcat (for debugging purposes). Now I wanna run this in Heroku and I follow the tutorial in https://devcenter.heroku.com/articles/java-webapp-runner

But when I run the command java -jar target/dependency/webapp-runner.jar target/*.war the following error is giving me:

javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

I have in my project the following files in webapp/WEB-INF: application-context.xml, servlet.xml and web.xml. The jndi configuration in application-context is:

<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/standard"/>

How can I fix this error

1
It looks like there may be a dependency that is either inject by Tomcat, or Eclipse, that is not present when running with webapp-runner. What JAR file includes the org.jnp.interfaces.NamingContextFactory class? Can you put that on the classpath? - codefinger
I'm using maven to deal with all the dependencies. - amachado
Which of your dependencies includes the org.jnp.interfaces.NamingContextFactory class? - codefinger

1 Answers

0
votes

I had the same issue with a spring 3 / tomcat configuration, making it run on heroku, and I just resolved it, I had this in my application-context.xml

  <bean id="dataSource"
      class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:comp/env/jdbc/catWDB</value>
    </property>
</bean>

And a file on src/main/webapp/META-INF/context.xml which had the URL, user, password and other variables.

I replaced the bean dataSource in application-context.xml with

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://SERVER:3306/DATA_BASE?zeroDateTimeBehavior=convertToNull&amp;autoReconnect=true"/>
    <property name="username" value="USERNAME"/>
    <property name="password" value="PASSWORD"/>
</bean>

I now I can deploy using heroku's web-app-runner adding this command

web: java -jar target/dependency/webapp-runner.jar target/*.war --port $PORT

to the Procfile