aspose file tools*
The moose likes Java in General and the fly likes Locating a jar file relative to the application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Locating a jar file relative to the application" Watch "Locating a jar file relative to the application" New topic
Author

Locating a jar file relative to the application

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Hello all:

I have a class C that is in a jar file. The class looks for resources in 3 other jar fils. All the jar files are located in the lib directory of an application.

How can I make class C find those jar files? I need to get the URL of the required jars.

I tried
URL url = class.getResource("A.jar");
URL url = class.getResource("\\A.jar");
URL url = class.getResource("..\\A.jar");

but nothing is working. Any ideas?

Thanks,


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Saurabh Deshpande
Ranch Hand

Joined: Aug 09, 2007
Posts: 33
hi,
i dont think you need to do anything in the code.
you simply need to add the jars to the CLASSPATH
and it will be taken care of.

let me know if the problem still persits after adding the jars to CLASSPATH


Saurabh Deshpande.
SCJP, SCWCD, SCEA Part 1
Doing Part 2 now....
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
What about using the JarURLConnection class?

JarURLConnection Javadoc



I hope that helps!
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
[Hanna Habashy:]the jar files are located in the lib directory of an application.

What application ?

http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html
[ September 18, 2007: Message edited by: Nicholas Jordan ]

"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Locating a jar file relative to the application