Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Accessing Resources Embedded in a Dynamically Loaded JAR

Posted on 2010-11-19
4
Medium Priority
?
434 Views
Last Modified: 2012-05-10
I am dynamically loading a JAR and succesfully accessing one of its classes. I am doing this with JarClassLoader. FYI, I was also able to successfully do this with URLClassLoader.

My problem is that the JAR class that I am instantiating is unable to access an XML file cotained in one of the JAR's packages/directories --- a java.io.FileNotFound exception results. Things work fine when I load the JAR on the classpath, but I must do the dynamic load given the architecture within which this has to work.

....any suggestions....anyone?
0
Comment
Question by:robertgw31
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 34177150
pass the system classloader as the parent of the classloader you are creating

http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getSystemClassLoader()
0
 

Expert Comment

by:robertgw
ID: 34179715
I assumed that the system classloader was by default the parent of the classloader I was creatging, but I will try this.  This is interesting that establishing the system classloader as the parent of the classloader within which theJAR is being loaded is necessary for a class within that JAR to access a resource that is also within that JAR.
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 37471900
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question