Skip to content
Advertisement

EJB 3.0 test client working without maven but not with

here is my problem, I made an EJB with maven and 2 test clients,

  • a test client without maven, only added jnp-client and the EJB to it’s class path, work like a charm
  • a test client using MAVEN, added the EJB through the POM and jnp-client, does not work

this is my EJB :

it’s POM :

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.toto.mp</groupId>
  <artifactId>MyFirstMavenEjb</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>ejb</packaging>
  <name>MyFirstMavenEjb</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>6.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

   <!-- setting default EJB2 to EJB3 -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ejb-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <ejbVersion>3.0</ejbVersion>
        </configuration>
      </plugin>

    </plugins>
  </build>
</project>

this is my first test client, the one without maven wich has no problem whatsoever to speak with the EJB

this is my second test client, using maven, it cannot speak with the EJB, all I’m getting is :

Context lookup finished
Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.toto.mp.MyFirstMavenEjb.TestMavenEjb
    at com.toto.mp.TestClientMavenEjb.App.main(App.java:27)

It’s POM :

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.toto.mp</groupId>
  <artifactId>TestClientMavenEjb</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>TestClientMavenEjb</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
  <!-- pour la dependance jnp-client, besoin de la version 5.0.3.GA -->
  <repositories>
    <repository>
      <id>Jboss</id>
      <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
        <groupId>org.jboss.naming</groupId>
        <artifactId>jnp-client</artifactId>
        <version>5.0.3.GA</version>
    </dependency>
    <dependency>
        <groupId>com.toto.mp</groupId>
        <artifactId>MyFirstMavenEjb</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>

Both clients have the same main :

public static void main( String args[] ) throws NamingException
{
    Hashtable env = new Hashtable(); 
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 
    env.put(Context.PROVIDER_URL, "localhost"); 
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" ); 
    Context ctx = new InitialContext(env);
        System.out.println("Context lookup finished");
        
        TestMavenEjb proxy = (TestMavenEjb)(ctx.lookup("TestMavenEjbBean/remote-com.toto.mp.MyFirstMavenEjb.TestMavenEjb"));
        System.out.println(proxy.getClass());
        
        System.out.println("do something!");
        
        proxy.doSomething();
}

So, anybody has even the slightest idea about why the maven test client is not working?

Jboss 5.1.0.GA Eclipse indigo Maven 3.0.4

Advertisement

Answer

The awnser was quite simple but couldn’t have been found by what I posted 😡

I was using a jee6 archetype and Jboss 5.1.0.GA is not compatible with jee6. If I uses a jee5 archetype I have no problems making them talk.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement