File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes JAR execution problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAR execution problems" Watch "JAR execution problems" New topic

JAR execution problems

Bryan Lemmer

Joined: Feb 01, 2007
Posts: 11
Hi all,

I am having a problem executing my main java class from a executable jar.

I use the standard "hello world" app to test the program. i complile the program and run it through the command prompt and it all worked fine.

I then use the following statement "jar cvfm test.jar manifest.txt *.class"
which creates the jar file but when i double click on the file nothing happens???

am i doing something wrong or is there a setting somewhere that i need to set.


Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
Is there a Main-Class header in your manifest file ?

Bryan Lemmer

Joined: Feb 01, 2007
Posts: 11
here is the code for the class and the mainifest entry:

public class mainTest
public static void main(String args[])
System.out.println("this is the correct way to run a java app");


Main-Class: mainTest
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15100

What happens if you type this on the command line to run the application:

java -jar test.jar

Do you get any error messages or does the program run as you'd expect?

Note: Your test program prints out a line of text to the console window. If you start an executable JAR file by double-clicking it, the console window is not opened, and you won't see the output of your program. So, you don't see anything happen.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Bryan Lemmer

Joined: Feb 01, 2007
Posts: 11
Thanks Jesper,

I am an IDIOT!! when executing it from the comand prompt it prints the line. Another question while we are on the subject... why doesnt it print a line to the command prompt if i have it open and then double click on the jar file?

I agree. Here's the link:
subject: JAR execution problems
It's not a secret anymore!