6 Replies Latest reply on Apr 18, 2013 9:46 AM by jack chen

    java.lang.ClassNotFoundException from Service Module Loader

    jack chen Newbie

      Hi all

      In my project I created a resteasy web service.  There are two jave projects and A dynamic web application and one EAR. I package two jave projects to two jar files(model.jar) into the EAR. In the web application one jar called the other one. I put the Class-Path: into MyDAO.jar file's manifest.mf file. When I called the web service I got

      java.lang.ClassNotFoundException: model.User from [Module "deployment.MyEAR.ear.MyDAO.jar:main" from Service Module Loader]

      at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

          at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_17]

          at java.lang.Class.forName(Unknown Source) [rt.jar:1.7.0_17]

       

      model.user class is in model.jar . Then I also try to put the model.jar into the EAR/lib. It still does not works.

       

      Can anyone help me? thanks a lot

        • 1. Re: java.lang.ClassNotFoundException from Service Module Loader
          Nicklas Karlsson Master

          I must say you lost me there a bit but the rule is that if you in an EAR have a WAR as a web module and stuff in JAR files in the EAR/lib, the WAR should see classes in those JARs. It's the REST WS in the WAR that needs classes from the JAR, right?

          • 2. Re: java.lang.ClassNotFoundException from Service Module Loader
            jack chen Newbie

            Thanks for reply.

            i first tried the Jboss-WS for EJB3 web service with Hibernate and Mysql in AS 7. It seems works. I used codes for EntityManager:

            @PersistenceContext(unitName="MorbaerhavenJPA") 

            public EntityManager entityManager;

             

            after that i used same way for Resteasy to get user from mysql:

            @Path( "/test" )

            public class RestTest{

            //the same way for EJB web service

                @PersistenceContext(unitName="MyJPA") 

                 public EntityManager entityManager;

              @GET

               @Path("/user/{uid}")

               @Produces(MediaType.TEXT_HTML)

               public String getUser(@PathParam("uid") String id) {

                  UserDAOImpl useDAO=new UserDAOImpl(entityManager);

                   User u=(User) useDAO.find(new Integer(1));

                    return u.getName();

                   }

              }

            I first package the jars into the EarContent and also add the jars in the class manifest.mf in the web module then in the web module can use the classes in the jars. In the eclipse there are no compile error and i can run it run the JBoss 7.1.1. only when the web service client called the service. then it will throw exception as before.

            • 3. Re: java.lang.ClassNotFoundException from Service Module Loader
              jack chen Newbie

              sorry the model.jar is the JPA jar

              The second post just explain why i got exception. I do not know if it can make you clear about my problem. Thanks.

               

              But when I debug the codes it seems the entityManger in the code is null. But the server did not show nullpoint exception. instead it shows the exception i showed in the first post.

              • 4. Re: java.lang.ClassNotFoundException from Service Module Loader
                Nicklas Karlsson Master

                You might be debugging different code from what was deployed. You shouldn't need to add anything to the manifest if you have a war and jars in the ear lib. Can you unzip the deployment archives and verify the class is really there?

                • 5. Re: java.lang.ClassNotFoundException from Service Module Loader
                  jack chen Newbie

                  Thanks for reply.

                  I had take a look the jar use the JD decompiler. The codes are there. Then I create a dynamc web appliction with servlet,  EJB application with stateless session EJB and  EJB web service three application into same EAR. Use the almost same codes:

                  @PersistenceContext(unitName="MyJPA") 

                  public EntityManager entityManager;

                  The entityManager are all injected correctly

                  Only Resteasy danymic web application can not inject . The entityManager is null. I google. There are some post for inject EJB to REstEasy. It seems the EJB can inject entitymanager then i will put above codes into EJB. and then from RESTEasy web service use the codes

                  InitialContext ctx;

                   

                  ctx = new InitialContext();

                  ctx.lookup("java:global/MyEAR/myEJB/GerenicDAO");

                  • 6. Re: java.lang.ClassNotFoundException from Service Module Loader
                    jack chen Newbie

                    It seems the RestEasy web application can not inject entitymanage and @EJB(It may have ways, but right now i  can not find one) so I tried to use the

                    InitialContext ctx;

                     

                    ctx = new InitialContext();

                    ctx.lookup("java:global/MyEAR/myEJB/GerenicDAO");

                    I do not if it is right way to do it? Thanks