• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ejb ClassLoader  RSS feed

 
Anibal Gimenez Canicoba
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get a class from a jar inside of an ear file(Always from an Ejb), but I get ClassNotFoundException... Wich is the right way to do that?

I'm trying with this:

Class c1 = Class.forName("com.product.MyClass", true,
ClassLoader.getSystemClassLoader());

"MyClass" is inside of a jar and the jar inside the ear.

any idea?
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In J2EE your should only use the Thread.currentThread().getContextClassLoader(). This way the container has to freedom to load the EJBs as necessary but still can provide you with an appropriate class loader to find the classes.

Secondly you need to make sure that the Class-Path in the Manifest.mf file (the one of the JAR file that is containing the EJB) is pointing to the JAR file your trying to load from. The path of this Class-Path has to be set relative to the EAR's root meaning that this:
Class-Path: ./lib/test.jar
would make 'test.jar' inside the EAR's 'lib' directory available to you.

-Andy
 
Anibal Gimenez Canicoba
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's working!!!

Thank you

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!