-
1. Re: java.lang.ClassNotFoundException from Service Module Loader
nickarls Apr 17, 2013 3:20 PM (in response to jackchen)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
jackchen Apr 17, 2013 5:30 PM (in response to nickarls)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
jackchen Apr 17, 2013 5:45 PM (in response to jackchen)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
nickarls Apr 18, 2013 2:05 AM (in response to jackchen)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
jackchen Apr 18, 2013 9:13 AM (in response to nickarls)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
jackchen Apr 18, 2013 9:46 AM (in response to jackchen)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