1 Reply Latest reply on Apr 25, 2013 11:57 AM by eildosa

    Cannot make my maven test client to speak with my EJB, missing jar?

    eildosa Newbie

      Hi, 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 :

       

       

      [img]http://img11.hostingpics.net/pics/480421EJB1.png[/img]

       

       

      it's POM :

       

       

      [code]

      <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.thongvan.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>

      [/code]

       

       

       

       

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

       

       

      [img]http://img11.hostingpics.net/pics/974963EJB0.png[/img]

       

       

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

       

       

      [code]

      Context lookup finished

      Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.thongvan.mp.MyFirstMavenEjb.TestMavenEjb

                at com.thongvan.mp.TestClientMavenEjb.App.main(App.java:27)

       

       

      [/code]

       

       

      [img]http://img11.hostingpics.net/pics/651692EJB2.png[/img]

       

       

      It's POM :

       

       

      [code]

      <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.thongvan.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.thongvan.mp</groupId>

                            <artifactId>MyFirstMavenEjb</artifactId>

                             <version>0.0.1-SNAPSHOT</version>

                </dependency>

        </dependencies>

      </project>

      [/code]

       

       

       

       

      Both clients have the same main :

       

       

      [code]

          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.thongvan.mp.MyFirstMavenEjb.TestMavenEjb"));

                          System.out.println(proxy.getClass());

       

                          System.out.println("do something!");

       

                          proxy.doSomething();

          }

      [/code]

       

       

      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

       

      Also I did some poking around by printing a toString on both context lookup here is what I got :

       

      [b]Maven project (not working)[/b]

      Reference Class Name: Proxy for: com.thongvan.mp.MyFirstMavenEjb.TestMavenEjb

      Type: ProxyFactoryKey

      Content: ProxyFactory/MyFirstMavenEjb/TestMavenEjbBean/TestMavenEjbBean/remote

      Type: EJB Container Name

      Content: jboss.j2ee:jar=MyFirstMavenEjb.jar,name=TestMavenEjbBean,service=EJB3

      Type: Proxy Factory is Local

      Content: false

      Type: Remote Business Interface

      Content: com.thongvan.mp.MyFirstMavenEjb.TestMavenEjb

      Type: Remoting Host URL

      Content: socket://localhost:3873/

       

       

       

       

      [b]regular project (working)[/b]

      Proxy to jboss.j2ee:jar=MyFirstMavenEjb.jar,

      name=TestMavenEjbBean,

      service=EJB3 implementing [interface com.thongvan.mp.MyFirstMavenEjb.TestMavenEjb]