Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!