Solved

Accessing Resources Embedded in a Dynamically Loaded JAR

Posted on 2010-11-19
4
416 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 500 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 26

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now