Re: ClassNotFoundException inside jar



Tha jar is in thw WEB-INF/lib folder. I am not getting classNotFound
for the jar. But inside the class in jar there is a line

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

and it is for mypackage.myclass that I get a ClassNotFoundException.
mypackage.myclass resides under WEB-INF/lib.

Regards,
Gaurav

On Jun 28, 11:49 pm, Manish Pandit <pandit.man...@xxxxxxxxx> wrote:
On Jun 28, 11:34 am, Gaurav <gaurav1...@xxxxxxxxx> wrote:



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

Can you try putting the jar file in the WEB-INF/lib folder of your
webapp?

-cheers,
Manish


.



Relevant Pages

  • 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)
  • Re: .jar files and Class-Path
    ... > This causes a ClassNotFoundException, even if I include the file ... > inserting the following line into my program's jar file's manifest: ... and the jar file I need ... The best way is to use your Java Runtime Environment. ...
    (comp.lang.java.help)
  • 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 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)