2 Replies Latest reply: Apr 1, 2011 9:35 AM by Steve Maring RSS

problem with JNDI and embedded JBoss 6 in Maven

Steve Maring Newbie

I seem to have a "damned if I do" and "damned if I don't" sort of problem with setting a jndi.properties file.

 

If I don't set a jndi.properties file, then my app server seems to start up just fine:

 

16:18:38,392 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.0.0.Final "Neo"] Started in 25s:969ms

 

but my unit test fails with:

 

<error message="Could not start container" type="org.jboss.arquillian.spi.client.container.LifecycleException">org.jboss.arquillian.spi.client.container.LifecycleException: Could not start container

    at org.jboss.arquillian.container.jbossas.embedded_6.JBossASEmbeddedContainer.start(JBossASEmbeddedContainer.java:102)

...

    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)

    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)

    at javax.naming.InitialContext.lookup(InitialContext.java:392)

    at org.jboss.arquillian.container.jbossas.embedded_6.JBossASEmbeddedContainer.initDeploymentManager(JBossASEmbeddedContainer.java:178)

    at org.jboss.arquillian.container.jbossas.embedded_6.JBossASEmbeddedContainer.start(JBossASEmbeddedContainer.java:98)

    ... 76 more

</error>

 

 

If I do throw a jndi.properties file into the classpath of my unit test with:

 

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

java.naming.provider.url=jnp://localhost:1099

 

then the app server does not even start up and fails with:

 

ERROR [DefaultJndiBinder] Unable to create JNDI subcontext for Bean Validation Factories: javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]

 

 

my pom file looks like this:

 

    <properties>

        <arquillian.version>1.0.0.Alpha5</arquillian.version>

        <jbossas.version>6.0.0.Final</jbossas.version>

    </properties>

 

    <build>

          <plugins>

 

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-ejb-plugin</artifactId>

                <version>2.3</version>

                <configuration>

                    <ejbVersion>3.1</ejbVersion>

                    <generateClient>true</generateClient>

                </configuration>

            </plugin>

 

        </plugins>

    </build>

 

    <profiles>

 

        <profile>

            <id>integration-test</id>

            <build>

                <plugins>

                    <plugin>

                        <groupId>org.apache.maven.plugins</groupId>

                        <artifactId>maven-surefire-plugin</artifactId>

                        <version>2.8</version>

                        <configuration>

                            <systemProperties>

                                <property>

                                    <name>log4j.configuration</name>

                                    <value>test-log4j.xml</value>

                                </property>

                            </systemProperties>

                            <additionalClasspathElements>

                                  <additionalClasspathElement>${project.build.directory}/jboss-${jbossas.version}/client/jbossws-native-client.jar</additionalClasspathElement>

                                  <additionalClasspathElement>${project.build.directory}/jboss-${jbossas.version}/server/default/deploy/jbossweb.sar</additionalClasspathElement>

                            </additionalClasspathElements>

                            <trimStackTrace>false</trimStackTrace>

                            <forkMode>once</forkMode>

                            <argLine>

                                -Xmx512m

                                -XX:MaxPermSize=256m

                                -Djava.net.preferIPv4Stack=true

                                -Djava.util.logging.manager=org.jboss.logmanager.LogManager

                                -Djava.endorsed.dirs=${project.build.directory}/jboss-${jbossas.version}/lib/endorsed

                                -Djboss.home=${project.build.directory}/jboss-${jbossas.version}

                                -Djboss.boot.server.log.dir=${project.build.directory}/jboss-${jbossas.version}

                            </argLine>

                        </configuration>

                    </plugin>

 

                    <plugin>

                        <groupId>org.apache.maven.plugins</groupId>

                        <artifactId>maven-dependency-plugin</artifactId>

                        <version>2.2</version>

                        <executions>

                            <execution>

                                <id>unpack</id>

                                <phase>process-test-classes</phase>

                                <goals>

                                    <goal>unpack</goal>

                                </goals>

                                <configuration>

                                    <artifactItems>

                                        <artifactItem>

                                            <groupId>org.jboss.jbossas</groupId>

                                            <artifactId>jboss-as-distribution</artifactId>

                                            <version>${jbossas.version}</version>

                                            <type>zip</type>

                                            <overWrite>false</overWrite>

                                            <outputDirectory>${project.build.directory}</outputDirectory>

                                        </artifactItem>

                                    </artifactItems>

                                </configuration>

                            </execution>

                        </executions>

                    </plugin>

 

                </plugins>

            </build>

        </profile>

    </profiles>

 

    <dependencies>

 

        <dependency>

            <groupId>org.jboss.arquillian</groupId>

            <artifactId>arquillian-junit</artifactId>

            <version>${arquillian.version}</version>

            <scope>test</scope>

        </dependency>

 

        <dependency>

            <groupId>org.jboss.arquillian.container</groupId>

            <artifactId>arquillian-jbossas-embedded-6</artifactId>

            <version>${arquillian.version}</version>

            <scope>test</scope>

        </dependency>

 

 

        <dependency> 

            <groupId>org.jboss.jbossas</groupId> 

            <artifactId>jboss-as-depchain</artifactId> 

            <version>${jbossas.version}</version> 

            <type>pom</type> 

            <scope>test</scope> 

        </dependency>

 

    </dependencies>

 

 

    <dependencyManagement> 

        <dependencies> 

            <dependency> 

                <groupId>org.jboss.jbossas</groupId> 

                <artifactId>jboss-as-depchain</artifactId> 

                <version>${jbossas.version}</version> 

                <type>pom</type> 

                <scope>import</scope> 

            </dependency> 

        </dependencies> 

    </dependencyManagement>

 

 

my unit test looks like this:

 

@RunWith(Arquillian.class)

public class PersonTest {

 

    @Deployment

    public static Archive<?> createDeployment() {

        return ShrinkWrap.create(JavaArchive.class, "test.jar")

            .addClasses(PersonDAO.class,PersonDAOBean.class)

            .addManifestResource("META-INF/persistence.xml", ArchivePaths.create("persistence.xml"));

    }

 

    @PersistenceContext

    EntityManager em;

 

    @Inject

    UserTransaction utx;

 

    @EJB

    private PersonDAO personDAO;

 

    @Test

    public void testEntityManager() {

 

    }

}

 

 

and I kick off the test with:   mvn -Pintegration-test test

 

Thanks,

Steve Maring

Tampa, FL