Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

ClassNotFoundException inside jar

Thread view: 
Gaurav - 28 Jun 2007 19:34 GMT
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
Manish Pandit - 28 Jun 2007 19:49 GMT
> Hi,
> I have a method getData() in class DataAccess which internally calls a
[quoted text clipped - 29 lines]
> TIA,
> Gaurav

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

-cheers,
Manish
Gaurav - 28 Jun 2007 20:35 GMT
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

> > Hi,
> > I have a method getData() in class DataAccess which internally calls a
[quoted text clipped - 35 lines]
> -cheers,
> Manish
Manish Pandit - 28 Jun 2007 20:51 GMT
> 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
[quoted text clipped - 48 lines]
>
> - Show quoted text -

Interesting..how about putting mypackage.myclass in the WEB-INF/
classes folder instead of WEB-INF/lib?

-cheers,
Manish
Gaurav - 28 Jun 2007 21:00 GMT
Ah sorry. I meant mypackage.myclass is under WEB-INF/classes folder.

> > 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
[quoted text clipped - 54 lines]
> -cheers,
> Manish
Roedy Green - 29 Jun 2007 01:36 GMT
>I would be grateful if someone could provide some suggestions.

you want to look at some system properties. See
http://mindprod.com/applets/wassup.html
to look at the classpath and the ext directory.

Dump them out at both places and look for differences.  Perhaps each
war file has its own classpath and these two are in different war
files.

use Class.getClassLoader to get a handle to the class loader then use
its various methods to help you figure out where it came from and if
it differs from the other one.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.