• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ejb ClassLoader

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's working!!!

Thank you

 
Paper jam tastes about as you would expect. Try some on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic