1 Reply Latest reply on Apr 30, 2009 6:34 PM by redguard

    HelloUser  simple ejb deployement in Jboss5 true myeclipse

    redguard

      h i'm trying to setup a basic exemple ejb project :

      my sessionBean :

      package ejb3inaction.example;
      
      import javax.ejb.Stateless;
      
      @Stateless
      public class HelloUserBean implements HelloUser{
      
       public void sayHello(String name){
       System.out.println("Hello "+ name + "Welcome t Ejb3!");
       }
      
      }


      my HelloUser class:
      package ejb3inaction.example;
      
      import javax.ejb.Remote;
      
      @Remote
      public interface HelloUser {
       public void sayHello(String name);
      }


      my persistence.xml file:

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
       http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
       <!--
       <persistence-unit name="chap1PU" transaction-type="JTA">
       <jta-data-source>chap1P</jta-data-source>
       </persistence-unit>
       -->
       <persistence-unit name="chap1PU">
       <jta-data-source>java:/chap1PU</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop" />
       <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
       </properties>
       </persistence-unit>
      </persistence>
      


      in jboss-5.0.1.GA/server/default/deploy

      i got a chap1PU-ds.xml and his content:
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- The Hypersonic embedded database JCA connection factory config -->
      <!-- $Id: hsqldb-ds.xml 76997 2008-08-12 22:29:19Z bstansberry@jboss.com $ -->
      <datasources>
       <local-tx-datasource>
       <jndi-name>chap1PU</jndi-name>
       <connection-url>jdbc:postgresql://localhost:5432/data</connection-url>
       <driver-class>org.postgresql.Driver</driver-class>
       <user-name>data</user-name>
       <password>data</password>
       <!-- sql to call when connection is created
       <new-connection-sql>some arbitrary sql</new-connection-sql>
       -->
      
       <!-- sql to call on an existing pooled connection when it is obtained from pool
       <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
       -->
      
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
       <metadata>
       <type-mapping>PostgreSQL 8.2</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>


      i have copied the jdbc postgresal jar in jboss lib

      and i got my test class:
      package ejb3inaction.client;
      
      
      
      import java.io.FileInputStream;
      import java.io.FileNotFoundException;
      import java.io.IOException;
      import java.io.Reader;
      import java.util.Properties;
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingEnumeration;
      import javax.naming.NamingException;
      
      import com.ibatis.common.resources.Resources;
      
      import ejb3inaction.example.HelloUser;
      import ejb3inaction.example.HelloUserBean;
      
      
      
      public class HelloUserClient {
       private static HelloUser helloUser;
      
       public static void main(String[] args) throws FileNotFoundException, IOException {
       try {
       //Context context = new InitialContext();
      
       Properties props = new Properties();
       props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       props.setProperty("java.naming.provider.url", "jnp://127.0.0.1:1099");
       props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
      
      
       Context context = new InitialContext(props);
       //helloUser = (HelloUser) context.lookup("chap1/"+ HelloUserBean.class.getSimpleName() + "/remote");
       String a = "java:/";
       NamingEnumeration ne = context.list(a);
       while (ne.hasMore()) {
       System.out.println("A: " + ne.next().toString());
       }
      
       //helloUser = (HelloUser) context.lookup("ejb3inaction.client.HelloUser");
       System.out.println("***>"+HelloUserBean.class.getSimpleName());
       //helloUser = (HelloUser) context.lookup(HelloUserBean.class.getSimpleName());
       // helloUser = (HelloUser) context.lookup("ejb3inaction.example."+ HelloUser.class.getSimpleName() + "/remote");
       helloUser = (HelloUser) context.lookup("HelloUserBean/remote");
       helloUser.sayHello("Curious George");
       } catch (NamingException e) {
       e.printStackTrace();
       }
       }
      }


      when i try to execute it it give me the following error:
      Failed to initalize plugin: org.jboss.logging.log4j.Log4jLoggerPlugin@173a10f, cause: org/apache/log4j/LogManager
      A: UserTransactionSessionFactory: $Proxy86
      A: jmx: org.jnp.interfaces.NamingContext
      A: persistence.unit:unitName=#chap1PU: org.hibernate.impl.SessionFactoryImpl
      A: queue: org.jnp.interfaces.NamingContext
      A: UUIDKeyGeneratorFactory: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory
      A: ClusteredConnectionFactory: org.jboss.jms.client.JBossConnectionFactory
      A: ClusteredXAConnectionFactory: org.jboss.jms.client.JBossConnectionFactory
      A: ConnectionFactory: org.jboss.jms.client.JBossConnectionFactory
      A: HelloUserBean: org.jnp.interfaces.NamingContext
      A: ProfileService: AOPProxy$0
      A: console: org.jnp.interfaces.NamingContext
      A: topic: org.jnp.interfaces.NamingContext
      A: HiLoKeyGeneratorFactory: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory
      A: TomcatAuthenticators: java.util.Properties
      A: XAConnectionFactory: org.jboss.jms.client.JBossConnectionFactory
      A: UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
      ***>HelloUserBean
      Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference
       at ejb3inaction.client.HelloUserClient.main(HelloUserClient.java:48)



      and when i try to add all the jars that are in /jboss-5.0.1.GA/client

      i got:
      21:35:03,482 INFO [ServerImpl] Starting JBoss (Microcontainer)...
      21:35:03,483 INFO [ServerImpl] Release ID: JBoss [Morpheus] 5.0.1.GA (build: SVNTag=JBoss_5_0_1_GA date=200902231221)
      21:35:03,484 INFO [ServerImpl] Bootstrap URL: null
      21:35:03,484 INFO [ServerImpl] Home Dir: /home/md/Desktop/jboss-5.0.1.GA
      21:35:03,484 INFO [ServerImpl] Home URL: file:/home/md/Desktop/jboss-5.0.1.GA/
      21:35:03,484 INFO [ServerImpl] Library URL: file:/home/md/Desktop/jboss-5.0.1.GA/lib/
      21:35:03,486 INFO [ServerImpl] Patch URL: null
      21:35:03,487 INFO [ServerImpl] Common Base URL: file:/home/md/Desktop/jboss-5.0.1.GA/common/
      21:35:03,487 INFO [ServerImpl] Common Library URL: file:/home/md/Desktop/jboss-5.0.1.GA/common/lib/
      21:35:03,487 INFO [ServerImpl] Server Name: default
      21:35:03,488 INFO [ServerImpl] Server Base Dir: /home/md/Desktop/jboss-5.0.1.GA/server
      21:35:03,488 INFO [ServerImpl] Server Base URL: file:/home/md/Desktop/jboss-5.0.1.GA/server/
      21:35:03,488 INFO [ServerImpl] Server Config URL: file:/home/md/Desktop/jboss-5.0.1.GA/server/default/conf/
      21:35:03,488 INFO [ServerImpl] Server Home Dir: /home/md/Desktop/jboss-5.0.1.GA/server/default
      21:35:03,488 INFO [ServerImpl] Server Home URL: file:/home/md/Desktop/jboss-5.0.1.GA/server/default/
      21:35:03,489 INFO [ServerImpl] Server Data Dir: /home/md/Desktop/jboss-5.0.1.GA/server/default/data
      21:35:03,489 INFO [ServerImpl] Server Library URL: file:/home/md/Desktop/jboss-5.0.1.GA/server/default/lib/
      21:35:03,489 INFO [ServerImpl] Server Log Dir: /home/md/Desktop/jboss-5.0.1.GA/server/default/log
      21:35:03,489 INFO [ServerImpl] Server Native Dir: /home/md/Desktop/jboss-5.0.1.GA/server/default/tmp/native
      21:35:03,489 INFO [ServerImpl] Server Temp Dir: /home/md/Desktop/jboss-5.0.1.GA/server/default/tmp
      21:35:03,490 INFO [ServerImpl] Server Temp Deploy Dir: /home/md/Desktop/jboss-5.0.1.GA/server/default/tmp/deploy
      21:35:04,385 ERROR [AbstractKernelController] Error installing to Described: name=JBossServer state=PreInstall
      java.lang.NoClassDefFoundError: org/jboss/reflect/spi/ClassInfo
       at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:179)
       at org.jboss.aop.util.ClassInfoMethodHashing.getMethodMap(ClassInfoMethodHashing.java:188)
       at org.jboss.aop.microcontainer.integration.AOPDependencyBuilder.getMethodAnnotationDependencies(AOPDependencyBuilder.java:204)
       at org.jboss.aop.microcontainer.integration.AOPDependencyBuilder.getAnnotationDependencies(AOPDependencyBuilder.java:158)
       at org.jboss.aop.microcontainer.integration.AOPDependencyBuilder.getDependencies(AOPDependencyBuilder.java:136)
       at org.jboss.kernel.plugins.dependency.DescribeAction.installActionInternal(DescribeAction.java:56)
       at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
       at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
       at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
       at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
       at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:106)
       at org.jboss.bootstrap.microcontainer.ServerImpl.doStart(ServerImpl.java:119)
       at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:394)
       at org.jboss.Main.boot(Main.java:209)
       at org.jboss.Main$1.run(Main.java:547)
       at java.lang.Thread.run(Thread.java:595)
      21:35:04,396 INFO [ServerImpl] Starting Microcontainer, bootstrapURL=file:/home/md/Desktop/jboss-5.0.1.GA/server/default/conf/bootstrap.xml
      Exception in thread "main" 21:35:04,653 INFO [ServerImpl] Runtime shutdown hook called, forceHalt: true
      java.lang.NoClassDefFoundError: org/jboss/beans/metadata/spi/BeanMetaDataFactory
       at java.lang.ClassLoader.defineClass1(Native Method)
       at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
       at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
       at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
       at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
       at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver.addClassBinding(DefaultSchemaResolver.java:237)
       at org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory.addJaxbSchema(SingletonSchemaResolverFactory.java:189)
       at org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory.<init>(SingletonSchemaResolverFactory.java:73)
       at org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory.<clinit>(SingletonSchemaResolverFactory.java:39)
       at org.jboss.bootstrap.microcontainer.TempBasicXMLDeployer.<clinit>(TempBasicXMLDeployer.java:58)
       at org.jboss.bootstrap.microcontainer.ServerImpl.doStart(ServerImpl.java:136)
       at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:394)
       at org.jboss.Main.boot(Main.java:209)
       at org.jboss.Main$1.run(Main.java:547)
       at java.lang.Thread.run(Thread.java:595)
      21:35:04,655 INFO [ServerImpl] Shutdown complete
      Shutdown complete
      Halting VM


      and thanks a lot for yur help