File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes JAR Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JAR Problems" Watch "JAR Problems" New topic

JAR Problems

Ronnie Coh

Joined: Mar 08, 2004
Posts: 13
Hi - I have 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

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

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

Any help/suggestions would be appreciated. Thanks... Ronnie
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It probably depends on what you want to do with these files. As for the text files, you can use Class.getResource() to obtain a URL to the files inside the JAR. You can then easily obtain input and output streams for the URL. This will work for zip files as well as long as you are streaming the resources yourself. See the Java API docs for the java.lang.Class and classes and package more details.



Java API Documentation
The Java Tutorial
Ronnie Coh

Joined: Mar 08, 2004
Posts: 13
Thanks - The two zipped files have printpreview classes. I can use them with the IDE but not standalone. The text file is input/lookup files. Thanks again.
I agree. Here's the link:
subject: JAR Problems
It's not a secret anymore!