Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

jar files

Posted on 2003-03-21
13
Medium Priority
?
303 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

581 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