tags:

views:

377

answers:

4

I have updated my ant build.xml file to include a new file and a new folder. After creating the .jar I check if they exist in the jar by 'unzip\extract', and they are there.

But when executing the .jar neither the folder or the file gets extracted.

Am I missing a step?

+2  A: 

Your application should be able to use the file directly from within the jar, no need for extracting it. Or do you mean something else?

sirprize
A: 

Are you doing something specific to extract the jar file? I ask because normally jar files are not extracted when executing them.

If you run "java -jar myJar.jar" or "java -cp myJar.jar com.example.MyMainClass" the jar files that is referenced will not be extracted. Java will load your classes and resources directly from the jar file without extracting it.

John Meagher
+2  A: 

Look into getResourceAsStream. It'll keep you from having to extract the files from the jar file. Unless that's your goal.

Allain Lalonde
Yeah, that's what I meant :)
sirprize
A: 

If you wrap your application up using One-JAR, you can specify an attribute in the Manifest file to extract files that you want (See the One-Jar-Expand manifest attribute).

As a bonus, you will also be able to wrap any dependent libraries along with your code, creating a single distributable jar.

James Van Huis