0

File PrintTest.java:

 public class PrintTest{ public static void main(String[] args){ System.out.println("Why are you executing me?"); } } 

File Manifest.txt

Main-Class: PrintTest 

My command I ran to compress to .jar:

jar cfm PrintTest.jar Manifest.txt PrintTest.class 

I also tried this (even though it doesn't matter):

jar cmf PrintTest.jar Manifest.txt PrintTest.class 

My Directory Structure: C:\Program Files\Java\jdk1.6.0_24\PrintTest_jar

PrintTest_jar: PrintTest.java, PrintTest.class, Manifest.txt, PrintTest.jar

When I double-click on the .jar file, nothing happens. No errors, nothing.

PrintTest.class runs fine from the command line. I'm also running on Windows.

3
  • What happens if you try to run it from the command line? java -jar PrintTest.jar Commented Feb 27, 2011 at 2:04
  • i get nothing from command line- however, PrintTest.class runs fine from it. Commented Feb 27, 2011 at 2:05
  • Are you sure, not even an error message? Commented Feb 28, 2011 at 9:55

4 Answers 4

2

When I double-click on the .jar file, nothing happens. No errors, nothing!

When launched like that, the console window will immediately disappear when the program has finished executing. To see the output, you should run the program from the console instead of double clicking the jar file.

edit: To delay the program termination, you could do this:

 Scanner scanner = new Scanner(System.in); System.out.print("Press Enter to exit..."); scanner.next(); 

However, I think it makes more sense to just run console applications from the console.

Sign up to request clarification or add additional context in comments.

2 Comments

is there a way to delay the end of the program so it doesnt end as soon as its done printing?
it now says theres an error with all 3 lines :P thats okay though. i just wanted to know why i couldnt see the application. vote up for you.
2

If I understand your question and the display of your manifest text file then you must ensure that the text file contains a new-line after the last line of text or it will not be processed properly. Please see this for more info: http://download.oracle.com/javase/tutorial/deployment/jar/modman.html

Comments

1

The code that was given to you to delay it is correct. However, you need to import an utility from Java libraries for it to work. Type in this before even your class body.

import java.util.Scanner 

1 Comment

It has to be assumed that he has this import or the class would not run from the command line.
1

My dear friend, your application is a DOS program and would only run in DOS, your did not create a GUI program, if it was a GUI program, it would at least display on the Computer.....DOS is meant for DOS..... sorry.

Comments