jar files

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)
java_boyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
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
anmascCommented:
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
anmascCommented:
How have you open the resource.properties file?
Open it with:
URL u = this.class.getResource("resource.properties");
props.load(u.openStream());

anmasc
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

SpartacuSCommented:
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
anmascCommented:
with this :
URL u = this.class.getResource("resource.properties"); it takes the propertie-file from the jar file.

anmasc
0
java_boyAuthor Commented:
objects =>

How do you add a ClassPath: attribute to a manifest file?
0
objectsCommented:
Include the line I posted above.

ClassPath: .

0
java_boyAuthor Commented:
At the start of the manifest file?
0
objectsCommented:
I don't think it matters.
0
java_boyAuthor Commented:
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
objectsCommented:
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
hamish5Commented:
try

ClassPath: yourResourceFileName.properties
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
objectsCommented:
How does that know which directory to find the file in?

And how are you opening your resource file?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.