jar help

S

SP

hi
i have been trying to make a jar file for the following files

hello.java
hello.class
with the following command

jar cf hello.jar hello.*

it is created and with
jar tf hello.jar

i am able to see the list of files which is in this case
META-INF/
META-INF/MANIFEST.MF
hello.class
hello.java

but it doesn't run with
java -jar hello.jar

following error appears
Failed to load Main-Class manifest attribute from
hello.jar

i tried to fix it with

jar cfm hello.jar mymainclass hello.*(after creating mymainclass with the
entry Main-Class: path.hello)

to no avail!
and another thing is although the dir META-INF is shown as above it is not
created in the folder..where is it created??

help please

Greetingz
Sunil
 
H

Haakon Nilsen

SP said:
i tried to fix it with

jar cfm hello.jar mymainclass hello.*(after creating mymainclass with the
entry Main-Class: path.hello)

Is the class hello in the package path? If it's not in any package, just
use "Main-Class: hello".

(Btw, class names in java should be capitalized, so use Hello instead of
hello for the class name.)
to no avail!
and another thing is although the dir META-INF is shown as above it is not
created in the folder..where is it created??

The jar program creates that directory, you need not worry about it.
 
G

ghl

SP said:
hi
i have been trying to make a jar file for the following files

hello.java
hello.class
with the following command

jar cf hello.jar hello.*

it is created and with
jar tf hello.jar

i am able to see the list of files which is in this case
META-INF/
META-INF/MANIFEST.MF
hello.class
hello.java

but it doesn't run with
java -jar hello.jar
[Assuming all your files are in the same directory...]
To run the application from a jar file by specifying the jar (hello.jar) the
jar file manifest.mf file must contain a header of the form
Main-Class: start-classname
This tells Java which class to load and call first.
You can modify the manifest.mf file in the jar by creating a file with the
needed header and updating the jar file using the jar command uvfm.
The file you need would be something like myMan.txt and would contain the
line
Main-Class: hello
The jar update would be
jar uvfm hello.jar myMan.txt
This will update the jar with the header in myMan.txt

You can then run the app with
java -jar hello.jar

By putting the jar file in the JAVA_HOME\jre\lib\ext directory you can run
the app with
java hello
from anywhere.
Have fun.
 
H

hh

SP said:
hi
i have been trying to make a jar file for the following files

hello.java
hello.class
with the following command

jar cf hello.jar hello.*

it is created and with
jar tf hello.jar

i am able to see the list of files which is in this case
META-INF/
META-INF/MANIFEST.MF
hello.class
hello.java

but it doesn't run with
java -jar hello.jar

following error appears
Failed to load Main-Class manifest attribute from
hello.jar

i tried to fix it with

jar cfm hello.jar mymainclass hello.*(after creating mymainclass with the
entry Main-Class: path.hello)

to no avail!
and another thing is although the dir META-INF is shown as above it is not
created in the folder..where is it created??

help please

Greetingz
Sunil

To add to the other two responses, you might find a tool such as JavaJar
useful: http://pivotonic.com/
 
L

Liu, Chunyen

use "jar cvf hello.jar hello.class"
There is no need to include the source code (*.java)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top