• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you access a file/jar from an executable jar which contains that file/jar?  RSS feed

 
Richard Mccaff
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So let's say i have an executable jar and inside that jar is a bunch of files. How do I access files within my jar?

assuming like, a main class is currently running and that is what's inside the manifest file as the main class inside that executable jar..
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say you want to access files in the jar, do you mean Java class files (use classes in the Jar in your code), or are you talking about resources (such as text files of images etc)?
 
Richard Mccaff
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike. J. Thompson wrote:When you say you want to access files in the jar, do you mean Java class files (use classes in the Jar in your code), or are you talking about resources (such as text files of images etc)?


Resources. java class files are considered resources as well right? what's the difference?
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is that normally to load a class from a jar you put the jar in the classpath and then being able to use classes in it becomes automatic. You rarely want to access the binary version of a class in your code.

Whereas to access a resource from a jar, such as an image or a properties file, you use the getResource() or getResourceAsStream() method of a class, normally a class which also came from the jar.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!