Failed to create functional JAR

J

JPractitioner

Hi guys,

I'm using windows 2k server with
Java version "1.5.0_06",
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
and
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing).


the followings are the steps i went through which lead me to this
problem.

1. Got my cmd promt to the working directory where i have all my
..classes
2. Typed command: jar cf MyJarFile.jar *.class
3. Created a manifest file, named it "update.txt" with the following
content
Manifest-Version: 1.0
Main-Class: MyMainClass
Created-By: 1.5.0 (Sun Microsystems Inc.)
4. Typed command: jar umf update.txt MyJarFile.jar.
5. I got the following output on the cmd prompt
Feb 26, 2006 4:59:27 PM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Manifest-Version
Feb 26, 2006 4:59:27 PM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Created-By
6. I tried double clicking MyJarFile.jar, the mouse cursor changed to
the hourglass, and at the taskmanager, on the process tab, i saw
javaw.exe was run. (was a 7768 K process)
7. No 6 scenario only happened for one ore two seconds, then the mouse
cursor returns to normal pointer image and the javaw.exe was turned
off.
8. I end up with nothing being run :(
9. googling for answers and posting in smart java people's forum (yes,
this google group)

Please help me.
Thanks (a lot) in advance :)
 
J

JPractitioner

I also found that, not only that i cannot run "MyJarFile.jar",
I also cannot run "OtherJarFileFromInternet.jar".
Same outcome (refering to no 8 above).

:((
 
H

hiwa

You must have used a jar cmf command from the
start for your class files *and* manifest file. In other
words, you should have had all the required files
at hand from the start.
 
J

JPractitioner

hi hiwa, thx for ur reply.
I already did as u suggested, but the outcome was the same.

i did
jar cmf MyManifestFile.txt MyJarFile.jar *.class

However, this time there was no warnings as encountered with my steps
(refering to no 5 of my first post for this thread)

Thanks anyway..but i am still not getting it working. please help.


p/s: i ve done this before but with other pc (using similar steps), and
it worked.. and now its making me go "hmmm....." ing.
 
H

hiwa

Your text file for manifest should be a single line:

Main-Class: MyMainClass

A colon, a space and your class name.

These lines are automatically written by jar command runtime:

Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems

Making an executable jar file is simple and easy if all the
required files are in and under the current directory. I never
failed in making them.
 
J

JPractitioner

hi hiwa, yeah i tried your latest suggestions as well and its coming to
the same result as well.
and, i have all the classes there,,

i will try this on other machine. i suppose there is something wrong
with my jar tool
hmm...

thx anyway, hiwa :)
 
J

JPractitioner

i've tried using other sets of classes, and its working. but only for
that set of classes.
those are the same classes i did with the other pc i mentioned (btw,
the pc is of similar spec in terms of jvm and os = win2k pro)
and i still cannot run jars that i downloaded.

what have i done wrong?
 
C

Chris Uppal

hiwa said:
Your text file for manifest should be a single line:

Main-Class: MyMainClass

BTW. It's important to ensure (thanks to some dodgy coding by Sun) that the
line is terminated with a newline. DOS or Unix format is acceptable, Mac
format may be too, for all I know.

-- chris
 
H

hiwa

Try an extremely simple one, a same class file with main()
method and a same manif text, on both machines. If it does
work, or, it doesn't work, you must have some extremely
local boob in your hands. We can't see them remotely.
Our flesh must go to your room to view them.
 
R

Roedy Green

the followings are the steps i went through which lead me to this
problem.

Check out the hints under http://mindprod.com/jgloss/jar.html
and http://mindprod.com/jgloss/jarexe.html

Before you try running your jar, examine it with JarLook or Winzip or
some such to make sure all it as you expected. See
http://mindprod.com/products1.html#JARLOOK

If you are debugging, the last thing you want is javaw.exe which hides
the console where the error messages come out. Ether change the
association to java.exe or don't use double click, use java -jar
myjar.jar

see http://mindprod.com/jgloss/jre.html#TESTING
for instructions on fixing the association.
 
J

JPractitioner

Hi hiwa, thx for the reply..
well i ve tried to learn if i can successfully jar the class from the
following code..
but seems to be no chance at all for me.. the thing keep not working..

Anyway, thx for your idea


public class Try{
public static void main(String[] a){
System.out.println("THIS IS A TRY");

}
}

p/s: I cannot access the other pc at the moment :(
 
J

JPractitioner

Hi Roedy, thanks for your reply,
I had tried to use use java -jar
myjar.jar as you suggested and i can see the program is running OK!

Now the only thing is i cannot execute the JAR by double clicking on
it.
will check the links out. thanks man. :)
 
J

JPractitioner

I want to execute a console program.... (expecting too see the black
and white "dos" console when i double click on the jar). Previously i
only tried to use jar for GUI programs. So, will this be an issue? I
mean, can i use jar for console program?

Thanks in advance :)
 
J

JPractitioner

Guys, I think ive got it... Thanks a lot to all especially to Roedy
Green.
I found the followings at http://mindprod.com/jgloss/javawexe.html


The javaw.exe command is identical to java.exe, except that with
javaw.exe there is no associated console window. This implies you can't
get it to display the version with -version since there is no console
to display it on. Use javaw.exe when you don't want a command prompt
window to appear. The javaw.exe launcher will, however, display a
dialog box with error information if a launch fails for some reason.
When you assocate jar files with either java.exe or javaw.exe you will
control whether you can see the console output.

So, I ve reconfigure my windows file type jar configuration to run
(read at Making Jar Files Double Clickable from
http://mindprod.com/jgloss/jar.html) java.exe instead of javaw.exe.

However, The console did not wait untill i "press any key to continue".

It appeared on the screen for a while (1 or 2 seconds).. then it
disappeared.

Is there any way, that i could make the console to not just disappear
like that, but to have the "press any key to continue" option.

hiwa, u did a great job as well, now i only have to remember one line
for my manifest file, thx buddy :)
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top