Creating an Executable JAR file with sub directories
Ben Wong
Greenhorn
Joined: Mar 27, 2006
Posts: 19
posted
0
Hi
I know this is an age old problem, but I just cant seem to get it working. Im trying to create a clickable JAR file. I managed to create one on my mac OSX, but the JAR file has to be clicked in the same directory as the referenced files.
So how do I create a clickable JAR file that contains all the subdirectories and files/images?
Please could somebody try explaining this to me! Thank you
Jeroen T Wenting
Ranch Hand
Joined: Apr 21, 2006
Posts: 1847
posted
0
An executable jar is no different from any other jar except it has a single special line in the manifest.
Any jar can contain whatever directories you want, which will be available as resources on your classpath. Of course you can NOT access any of them as if they were directories on a filesystem, because they aren't.
That however is no problem as there are mechanisms like Class.getResourceAsStream() to get at the data.
42
Ben Wong
Greenhorn
Joined: Mar 27, 2006
Posts: 19
posted
0
I have managed to create the executable JAR. I also use class.getResource() to locate the path of the referenced files. However, for some reason, the JAR does not contain the referenced files.
What do i need to type in the command line to include the directories?
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
9
posted
0
Originally posted by Ben Wong: I have managed to create the executable JAR. I also use class.getResource() to locate the path of the referenced files. However, for some reason, the JAR does not contain the referenced files.
What do i need to type in the command line to include the directories?
You need to include the name of the directories on your command line.
Usage: jar {ctxu}[vfm0Mi] [jar-file] [manifest-file] [-C dir] files ... Options: -c create new archive -t list table of contents for archive -x extract named (or all) files from archive -u update existing archive -v generate verbose output on standard output -f specify archive file name -m include manifest information from specified manifest file -0 store only; use no ZIP compression -M do not create a manifest file for the entries -i generate index information for the specified jar files -C change to the specified directory and include the following file If any file is a directory then it is processed recursively. The manifest file name and the archive file name needs to be specified in the same order the 'm' and 'f' flags are specified.
Example 1: to archive two class files into an archive called classes.jar: jar cvf classes.jar Foo.class Bar.class Example 2: use an existing manifest file 'mymanifest' and archive all the files in the foo/ directory into 'classes.jar': jar cvfm classes.jar mymanifest -C foo/ .