File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAR execution problems" Watch "JAR execution problems" New topic
Author

JAR execution problems

Bryan Lemmer
Greenhorn

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.

HELP!!

Cheers
Bryan
Joanne Neal
Rancher

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


Joanne
Bryan Lemmer
Greenhorn

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");
}
}

manifest.txt

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

Joined: Aug 16, 2005
Posts: 14103
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
Bryan Lemmer
Greenhorn

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?

Bryan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAR execution problems