I'm trying to create the most basic proof-of-concept for integration testing a Java webapp that has an EJB dependency. I came across this article, which looks close to what I'm trying to do.
To create the simplest webapp possible, I used mvn archetype:generate
and selected the 'maven-archetype-webapp' option.
Then I altered the pom.xml
file to look like the following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.jwleeman</groupId>
<artifactId>ridgefield</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ridgefield Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>ridgefield</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.12.v20130726</version>
<configuration>
<systemProperties>
<systemProperty>
<name>java.naming.factory.initial</name>
<value>org.apache.openejb.client.LocalInitialContextFactory</value>
</systemProperty>
<systemProperty>
<name>java.naming.factory.url.pkgs</name>
<value>org.mortbay.naming</value>
</systemProperty>
</systemProperties>
<scanIntervalSeconds>100</scanIntervalSeconds>
<stopKey>stop</stopKey>
<stopPort>9099</stopPort>
<httpConnector>
<port>9090</port>
</httpConnector>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
However, when I run mvn clean install
, I get the following exception:
2015-01-06 11:29:23.524:INFO:oejs.Server:jetty-8.1.12.v20130726
2015-01-06 11:29:23.628:WARN:oejw.WebAppContext:Failed startup of context o.m.j.p.JettyWebAppContext{/,file:/Users/jeffreyleeman/maven-experiments/ridgefield/src/main/webapp/},file:/Users/jeffreyleeman/maven-experiments/ridgefield/src/main/webapp/
javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.openejb.client.LocalInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.openejb.client.LocalInitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
Can anyone help me out with what might be happening? Thanks so much!
UPDATE:
So I got past the first error above by moving the openejb-core
dependency to the jetty-maven-plugin itself, so under the <plugin>
element, I added the following:
<dependencies>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>
(and removed this <dependency/>
from its original place in the POM.)
Now I get the following error when running mvn clean install
:
[WARNING] Failed startup of context o.m.j.p.JettyWebAppContext{/ridgefield,file:/Users/jeffreyleeman/maven-experiments/ridgefield/src/main/webapp/},file:/Users/jeffreyleeman/maven-experiments/ridgefield/src/main/webapp/
javax.naming.NameNotFoundException: Name "comp/env" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:197)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:126)
Any ideas?