• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get the path to a jar file  RSS feed

 
Wes Hughes
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to generate a signature for a jar file within my application (could be standalone/web app/etc). To do that I need to get the path to the jar file. I thought that something like getClass().getResource("struts.jar").getFile() would do it but it doesn't (i.e. this throws an NPE within a struts app). The above syntax only works when you specify that the folder containing the jar is on the classpath, not the jar itself.

How can I do this without including the folder containing the jar on the classpath?

Thanks.
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose that obj is an instance of a class that belongs to struts.jar, you could do:
 
Wes Hughes
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks. Never had the opportunity to use that before.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!