Oleg, I'm afraid your answer is wrong - when you use the "-jar" option, you must specify the filename of the jar file, including the extension.
When you double-click a jar file to run it, it is run with javaw.exe, which is a special version of java.exe that does not open a console window. So if your program prints to the console window, nothing will be visible when you double click it.
What happens if you run it in a console window, with "java -jar Test.jar"? Nothing at all? You just get the prompt back, without any output?
Can you please post your source code and content of the manifest file?
Tom Malia wrote:HOWEVER, if I just try to execute the Jar file either from the command prompt or by double clicking on the file then, I don't get any errors but it just doesn't do anything. What am I doing wrong?
What you are doing wrong is expecting to see a console when you execute the jar that way. If you look into your Windows configuration you'll see that executable jars are configured to be run via the javaw.exe program, which doesn't use a console.
Joined: Aug 05, 2009
I kind of figured it had something to do with the while "System.out" not being the "console" when run by just executing the jar file.
as for code, it's the classic:
and the manifest file was just:
Where is the windows configuration that tells it to use javaw? Can I change it to use java.exe instead?
What if I wanted to write a java program that I could use to process things the way you do in Unix where you pipe stuff through other program?
For example, let's say I wanted to write a java app that could be used as a filter to do something like:
c:> type MyFile.txt | MyJavaProgram.jar > NewFile.txt
When you run your JAR-packaged program from the command line, by executing a command such as "java -jar Test.jar", then it will not use javaw.exe - it will only use javaw.exe when you double-click the JAR file in Windows.
So if you enter "java -jar Test.jar" in a command prompt, it should print "Hello World!" in the command prompt window. If it doesn't, then something strange is happening.
I don't know if it's easy to change it so that when you double-click a JAR, java.exe instead of javaw.exe will be used. You could probably change this by changing the file extension association in Windows. You shouldn't normally do that, and it probably won't really solve your problem. When you'd double-click your JAR file with the program shown, it would open a console window, print "Hello World!" and immediately close the console window again, so you'd only see a console window flash and disappear immediately again.
Redirecting output using > or | should work in Windows from the command prompt in the same way as in a terminal window in Unix.