• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

SystemClassLoader

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I load a class using JNLPClassLoader. This class uses other classes found in third party jars. The problem is that the third party jars use SystemClassLoader to access resources, which is wrong, the should use this.getClassLoader().
Trying to find a way around this problem I was wondering why resolveClass() is protected in ClassLoader class? Otherwise I could have published the classes after taking them through JNLP.
Thanks,
Cristian
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi cristian
Can you please explain us why you say "its wrong" to use SystemClassLoader instead of JNLPClassLoader?
What problem you are facing due to that behavior?
As far as my knowledge goes, if a class is loaded by one class loader then system tries to load all the subsequent reference classes by that class loader, right?
Also, the reason for resolveClass() to be protected might be- the API writer only wanted to allow access for resolveClass() to actually a "ClassLoader". If it were public then it could have been used by any stupid outside class which is not a ClassLoader and it would not have made sense. Again, to my knowledge, resolveClass() doesn't really do much except to resolve the class name and convert "." to "/" if its a package class and making sure that the class name makes sense...Though I could be wrong. This comes from my interaction with the resolveClass() implementation I went through to know what the heck resolveClass() do when I wrote my first class loader...
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cristian
in the last part of the post I mentioned about resolveClass() method as you seem to belive it to be the method you will want to access but to me it won't probably solve your issue, even if you were able to access it, as resolveClass() doesn't do much as I mentioned...
Regards
Maulin
 
Cristian Negresco
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The problem is that as JNLPClassLoader loaded the jars they are not visible for the SystemClassLoader.
As far as I know the SystemClassLoader searches for the classes in the classpath, but the clases are actually in a jws built directory from where just the JNLPClassLoader could load them. I couldn't even use those classes as the JWS modifies the names of the files that contain the classes. If I just copied the classes to the classpath it works.
So, if the classes in the jars would have used Class.forName() it would have been ok because the attempt to load the classes would have been made with the ClassLoader of the caller, that is the loader of the class in which the Class.forName() has been made. The SystemClassLoader does not have visibility to the classes loaded by the JNLPClassLoader.
About the resolveClass() I am not sure about how it works, from the docs I imagined it would be possible, having found a class with another ClassLoader to "publish" it, to make it visible, in the parent ClassLoader.
Cristian
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Cristian
so, when you mention,
"So, if the classes in the jars would have used Class.forName() it would have been ok"
I tend to believe that its not using Class.forName() in classes that are there in the jar files. Now, as its not using that way, it tries to download classes via SystemClassLoader...Am I correct in predicting what you want to imply?
Now, how do you know that its not using Class.forName()? Is there a "named" access to some classes instead of loading it dynamically via Class.forName()? In that case I guess again the JNLPClassLoader will be used to load those classes.
Also, it might be more helpful if you can post some more details about the Exception you might be getting and some specific code snippet where you think its failing...
Regards
Maulin
 
Cristian Negresco
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
See below.

hi Cristian
so, when you mention,
"So, if the classes in the jars would have used Class.forName() it would have been ok"
I tend to believe that its not using Class.forName() in classes that are there in the jar files. Now, as its not using that way, it tries to download classes via SystemClassLoader...Am I correct in predicting what you want to imply?
Cristian>>> Yes, you are.
Now, how do you know that its not using Class.forName()?
Cristian>>> I decompiled the classes. ;0)
Is there a "named" access to some classes instead of loading it dynamically via Class.forName()? In that case I guess again the JNLPClassLoader will be used to load those classes.
Cristian>>> I am not sure about you point, but the JNLPClassLoader is the single loader that knows where to find the classes. I don't know if this answers the question.
Also, it might be more helpful if you can post some more details about the Exception you might be getting and some specific code snippet where you think its failing...
Cristian>>>
the call is
LoginContet lc;
[...]
lc.login();

LoginContext is in one of the downloaded jars. It could be found because I am using JNLPClassLoader. Problem is that LoginContext tries to find a class named XYZLoginModuleProxy using SystemClassLoader.
And here is the exception:
java.lang.ClassNotFoundException: com.xxx.xyz.security.common.auth.module.proxy.XYZLoginModuleProxy
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:272)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
Regards
Maulin
Best Regards,
Cristian
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic