Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jar Problem

Status
Not open for further replies.

k4ghg

Technical User
Joined
Dec 25, 2001
Messages
192
Location
US
Hi - I have a JAR file that uses data files and two zipped files, but I can not get them to work. Every thing works file in my IDE when I work with JAR's files and the zipped files.

At first I included all the files in the JAR and used a Manifest file:

Main-Class: folder.mainName
Class-Path: folder.zipFile_1.zip folder.zipFile_2.zip

First the JAR would not read the dat files in the JAR. It did work when I put the data files in the JAR's folder.

a) Is there a way to get the JAR to read text files within the JAR.?


The JAR would not access the zip files. I reied putting them out side the JAR and changed the Manifest file without too much luck. Here is the file:

Main-Class: folder.mainName
Class-Path: zipFile_1.zip folderFile_2.zip

b) How can I get the JAR to read/use the resources in the zipped file?

Any help/suggestions would be appreciated. Thanks... Ronnie
 
Datafiles aren't search in the classpath.
That's the reason why it is called classpath, and not datapath.

In java.util. you find classes for reading from zip-files.
Use relative paths to find the zip-file, and make a startscript, to change to that well-defined base-dir, before starting your app.

Or use a property:

Code:
java -DDATADIR=/home/foo/.fooapp/datadir -jar fooapp.jar


seeking a job as java-programmer in Berlin:
 
Thanks Stefanwagner, I managed to get the JAR to access the zip files by putting them in the JAR's folder.

There is something that I am not clear at JARs. Does the "Class-Path" reffer to external programs or to the JAR itself? That is if lets say my JAR is in c:\ can I use d:\ for a "Class-Path"?

Does the zip classes in java.util also handle JAR files?

Thanks...Ronnie
 
The class-path inside a jar-Manifest refers to outer classes or directories or jar-files.
You may not access nested jar-files that way - for such behaviour you have to replace the classloader by a specialpurpose classloader.
I once found some in the web, but didn't get warm with the idea of using a different classloader.

I never used the zip classes to handle jar files in my code, but to zip a directory foo, I use jar:

Code:
jar -cfM foo.zip -C foo .
and never saw a problem when using zip to unzip jars or jar to unzip zips.
jar-files are - in my opinion - zip files, only by default (without using the 'M' switch) a manifest is added, but that's not a problem for zip-tools.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top