ClassNotFoundException inside jar



Hi,
I have a method getData() in class DataAccess which internally calls a
method in a class inside a jar. The method inside the jar has
somehting like this:

Class.getForName("mypackage.myclass").newInstance();

The class instantiation works perfectly fine when I call getData()
from a main() method inside DataAcess. But I get a
ClassNotFoundException when I try to access the getData() method from
a web application (servlet container-Tomcat).

For the sake of debugging I added the line
Class.getForName("mypackage.myclass").newInstance(); inside the
getData() method itself. I observed there was no error when this line
was executed in getData() even when accessing the method from the
servlet.

Thus I only get the ClassNot FoundException inside the jar when I try
to access the method from the web application.

Someone suggested that this could be a classloader issue as there are
multiple classloaders in case of servlet but I am not really sure how
to resolve it.

I would be grateful if someone could provide some suggestions.

Note: The class in the jar reads the class name (mypackage.myclass)
from an XML file but I did put a debugger and observed that the
correct name was being sent to the jar.

TIA,
Gaurav

.



Relevant Pages

  • Re: ClassNotFoundException inside jar
    ... I have a method getDatain class DataAccess which internally calls a ... method in a class inside a jar. ... The class instantiation works perfectly fine when I call getData() ... a web application (servlet container-Tomcat). ...
    (comp.lang.java.programmer)
  • Re: ClassNotFoundException inside jar
    ... I meant mypackage.myclass is under WEB-INF/classes folder. ... But inside the class in jar there is a line ... mypackage.myclass resides under WEB-INF/lib. ... ClassNotFoundException when I try to access the getData() method from ...
    (comp.lang.java.programmer)
  • Re: ClassNotFoundException inside jar
    ... But inside the class in jar there is a line ... mypackage.myclass resides under WEB-INF/lib. ... ClassNotFoundException when I try to access the getData() method from ...
    (comp.lang.java.programmer)