?
Solved

jar files

Posted on 2003-03-21
13
Medium Priority
?
296 Views
Last Modified: 2013-11-23
Under my root directory, I have 4 files:

manifest.mf, main.java, main.class, resource.properties

(Note: main.java has code to read information from resource.properties)

I create a jar file by entering:

jar -cmvf manifest.mf myFile.jar main.class

Then, if I run:

java -jar myFile.jar

it gives an error saying: missing resource file

But if I run:

java main

it finds the resource.properties file and works fine

Question:
How can I run the program as a jar file?

(Note: I do not have the option of entering:
jar -cmvf manifest.mf myFile.jar main.class resource.properties

because then, the resource.properties file is added to the jar file, and if I make any changes to resource.properties after that, the changes do not get read by my program)
0
Comment
Question by:java_boy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8185427
Try adding a ClassPath: attribute to your manifest that includes .

ClassPath: .


If that does not work then you'll need to run it using:

java -classpath myFile.jar;. main
0
 

Expert Comment

by:anmasc
ID: 8185879
On windows and macosx you can start the jar file by clicking. You have only to write that in your manifest-file:
Manifest-Version: 1.0
Main-Class: main
Created-By: 1.3.0_02 (Sun Microsystems Inc.)


Then you can start the jar file by cliking.
anmasc
0
 

Expert Comment

by:anmasc
ID: 8185894
How have you open the resource.properties file?
Open it with:
URL u = this.class.getResource("resource.properties");
props.load(u.openStream());

anmasc
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:SpartacuS
ID: 8186553
Because your resourse file is your own stuff, i think you cant access it from within a jar archive. Try leaving this one rsource file out of the .jar archive when you compile it, but in the same directory. Then try running your jar file as normal.
0
 

Expert Comment

by:anmasc
ID: 8187591
with this :
URL u = this.class.getResource("resource.properties"); it takes the propertie-file from the jar file.

anmasc
0
 

Author Comment

by:java_boy
ID: 8192335
objects =>

How do you add a ClassPath: attribute to a manifest file?
0
 
LVL 92

Expert Comment

by:objects
ID: 8192511
Include the line I posted above.

ClassPath: .

0
 

Author Comment

by:java_boy
ID: 8192517
At the start of the manifest file?
0
 
LVL 92

Expert Comment

by:objects
ID: 8192549
I don't think it matters.
0
 

Author Comment

by:java_boy
ID: 8198586
Oh, I think I know why your ClassPath instructions aren't working for me. I made a mistake at the very start of my question by saying that all these files are in the root directory. They are actually in a directory called: dev
which itself is in a directory called: new
which, in turn, is directly under the root directory.

How will that change your instructions, objects?
0
 
LVL 92

Expert Comment

by:objects
ID: 8198883
Then the ClassPath: attributes needs to specify the relative location of the directory containing the external resources. From the sound of your description this should be:

ClassPath: new/dev
0
 

Accepted Solution

by:
hamish5 earned 300 total points
ID: 8221420
try

ClassPath: yourResourceFileName.properties
0
 
LVL 92

Expert Comment

by:objects
ID: 8221524
How does that know which directory to find the file in?

And how are you opening your resource file?
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question