0 Replies Latest reply on Jul 7, 2013 2:23 PM by squarcio

    EJB java.lang.NoClassDefFoundError: javax/persistence/EntityManager

    squarcio

      Hello to all,

      I'm new to javaEE and JBoss AS and i'm trying to learn developing EJB applications but i have a problem i don't know how to solve.

      I use NetBeans 7.3 and JBoss AS 7.1.1.

      I have been created an EJB 3.1 module with an entity bean and a session bean with remote interface that performs the database operations using the entity bean.

      After i have been created a java application to access the EJB module:

      1. inside the library of the project i put the jboss-client.jar and the EJB module.jar files
      2. i have been created a config package with the jboss-ejb-client.properties file
      3. i lookup the bean with the method :

       

      public static ControllerPrenotazioniRemote lookupRemoteControllerPrenotazioni() throws NamingException {

              final Hashtable jndiProperties = new Hashtable();

              jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

       

              final Context context = new InitialContext(jndiProperties);

       

              final String appName = "";

              final String moduleName = "EJBModule1";

              final String distinctName = "";

              final String beanName = ControllerPrenotazioni.class.getSimpleName();

       

              final String viewClassName = ControllerPrenotazioniRemote.class.getName();

              System.out.println("Looking EJB via JNDI ");

              System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);

       

              return (ControllerPrenotazioniRemote) context.lookup("ejb:/EJBModule1/ControllerPrenotazioni!"

                      + ControllerPrenotazioniRemote.class.getName() + "?stateful");

       

          }

       

      I deploy the EJB module less problems,but when i try to run the java application i see thi error in the output tab of NetBeans:

       

      Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/EntityManager

          at controllers.ControllerPrenotazioni.trovaPrenotazione(ControllerPrenotazioni.java:133)

          at principale.Main.main(Main.java:22)

      Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityManager

          at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

          at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

          at java.security.AccessController.doPrivileged(Native Method)

          at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

          ... 2 more

      Java Result: 1

       

      I do not know where I'm wrong!Someone can help me to solve this problem?

       

      Thank you to all in advance....