• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Locating a jar file relative to the application  RSS feed

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about using the JarURLConnection class?

JarURLConnection Javadoc



I hope that helps!
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!