A quick search through the FAQ finds this page, which has some hints and links to further information.
If it terminates quickly, then that probably means there was an uncaught exception. Try running it from the command line like "java -jar xyz.jar". Then you'll have a chance to see the stack trace of the exception. [ May 03, 2006: Message edited by: Ulf Dittmer ]
Ping & DNS - updated with new look and Ping home screen widget
ok i changed the desktop to where it opens jar files with java.exe, but and blank black box pops up and then goes away really fast...
You should change the association so that Windows uses javaw.exe to open the .jar file. (The difference is that you don't get the console window.)
This is usually the default, but it might have got changed somehow. You can right click on a .jar file and choose "Open with..." to change the association.
Ernest's point about the manifest is important - otherwise "nothing" will happen when you double click the .jar file. Sometimes you actually want to see the console output - for error messages when the program is starting, or for debugging output that you print to System.out. One way to achieve this is to run the program from the command line with:
Joined: Jan 24, 2006
yeah, it works fine in the command prompt
and tried to get javaw.exe to open it and the hour glass came up and that
i did everything right...
guess my comp sucks or something
Joined: Oct 12, 2005
It might be a good idea to put a System.out.println("!!!") at the start of your main() method. You should be able to see this from the command prompt when you use the java -jar command. This will test that there is nothing wrong with the manifest.
When you say it works fine from the command prompt, what actually happens? I ask this because to be visible your program has to produce some non-console output (eg make a JFrame visible or whatever). What you are expecting to see is that running javaw.exe (via a double click) has exactly the same result as running java -jar (except for console output).
If the code is not too long perhaps you could post it.
Joined: Jan 24, 2006
this is what my mainfest file contains:
and here is the java file AVerage.java:
the program is very simple..
and when i do the: java -jar Average.jar, that works just fine,
the out put looks like this:
because i created my file like this: jar cmf Averagefest.txt Average.jar AVerage.class
all i want is for the command line to pop up when i double click on the file..
is quite effective in running your program in a console window. (Note the lack of "w" in the command name). There is still a problem because the window closes before you can read the answer! One way around this is to add a prompt, "Press <Enter> to exit..." and read a line of input from the console before exiting.
(There may be other bugs in your program, but they don't have anything to do with running it as a .jar)
To address your other question: you could write your own Swing component that interacts textually with the user, but this is not easy. Probably it is better if you are writing a graphical application to do things graphically (use controls and dialog boxes to gather and display information). And if you are using Scanner, launch the .jar with a script as described above.
Do (continue to) ask if I'm being unclear. There's a bit of a time lag - I guess we're in different time zones. [ May 05, 2006: Message edited by: Peter Brockway ]
Joined: Jan 24, 2006
I made an applet and jar'd it and the double click works just fine.
thanks for all the help, i guess for my average class i'll have to make it
a GUI to be able to double click it and use it.
but all i would have to do is have labels,
one for the line "Enter Number to be Averaged: "
and then one for "Enter the "+count+" Number: " // then have a
JTextfield 't' for input.
then i could do :
int answer = Integer.parseInt(t.getText()); int sum = 0; sum += answer;
and have some buttons, "add" and "average".
anyways, thanks again.
-Justin- [ May 05, 2006: Message edited by: Justin Fox ]