• Post Reply Bookmark Topic Watch Topic
  • New Topic

class not found  RSS feed

 
Manoj kumar A
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jar file containing two class files
Application.class and passingObj.class.This jar file is stored in a sub directory of current directory
I have another class namely Test.java which has main method
and a A file "StoringFile.txt "
from the main method iam loading the Application.class from the jar file using
URLClassLoader and calling a method in Applicaion.class by
"invokeMethod()" and passong an Object to the method.This Object I read from the "StoringFile.txt "
Objects in "StoringFile.txt " are made by "writeObj((Object)passingObj)".which i made separately.
In the Application.class ,iam type casting that Object with passingObj class.
The probem is when the StoringFile.txt is read for Object for passong to method in Application,in the main method.it says it could not find class "passingObj"
ie it does not find class from jar file ...i had set the url to this jar file when i made the URLClassLoader.
What is the problem here? is it because ,the url set is not correct?

 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can only find things that are in the classpath, it that in your classpath?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm understanding you right, the problem is that the Test class is loaded through the primordial class loader -- the default one -- and the Application class is loaded through your URLClassLoader. The URLClassLoader is the only one that knows how to find the passingObj class; the primordial class loader would need it to deserialize the object, but it doesn't know where to load it from.
One possible way to resolve this -- not necessarily a good way, but a way which should work -- would be to set the context class loader to be your URLClassLoader, at least while you're loading the object.

I'm sure there's a more elegant way to do this but I'm not sure what it is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!