need executable jar

Hello experts,
I am trying to create an executable jar file using latest jdk1.6.0 on Windows XP box.
I see this problem has come up before but I just cant follow the solutions given. It must be somjething very simple I am missing.
I have started with very simple HelloWorldApp.java file and using a batch file on cmd.exe to build.
My batch file is:
cd C:\MyHello
javac HelloWorldApp.java
java HelloWorldApp
jar cvf HelloWorld.jar HelloWorldApp.java

This works perfectly and the second line produces HelloWorldApp.class then the third line runs the file at least in cmd.exe.
The fourth line creates a jar file
When I try to run the jar file by double clicking on it I get error, "Failed to load Main-Class manifest attribute from HelloWorld.jar"
When I look at the contents of HelloWorld it shows that a default manifest was added.
I tried making a separate manifest file with
Main-Class: HelloWorldApp and typed jar umf manifest helloworld.jar into cmd.exe but got io error system cannot find the file specified.
My question is, what more do I have to do to be able to run the jar file without this error.
Here is the HelloWorldApp.java:
/**
 * The HelloWorldApp class implements an application that
 * simply prints "Hello World!" to standard output.
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}
bravotangoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>jar cvf HelloWorld.jar HelloWorldApp.java

Should be

jar cvf HelloWorld.jar HelloWorldApp.class
0
bravotangoAuthor Commented:
Thanks for quick reply CEHJ, I just tried that and same result
0
CEHJCommented:
You need to make a manifest file then

jar cvfm HelloWorld.jar yourmf.mf HelloWorldApp.class

In the meantime you should be able to run

java -cp HelloWorld.jar HelloWorldApp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

CEHJCommented:
The manifest file would be

Main-Class: HelloWordApp.class

with a couple of blank lines at end
0
bravotangoAuthor Commented:
Yes it still doesnt work and I can use java -cp HelloWorld.jar HelloWorldApp on the command line and it works perfectly there.
0
bravotangoAuthor Commented:
It is such a tiny project which starts with just one file all in one folder. Would be nice if someone could just run it with a similar batch file and get the same result to see whats wrong.
0
CEHJCommented:
Please show your last command
0
bravotangoAuthor Commented:
This is everything in my batch file:

javac HelloWorldApp.java
java HelloWorldApp
jar cvf HelloWorld.jar HelloWorldApp.java
jar umf manifest HelloWorld.jar

btw how do you make comments in a batch file?
0
CEHJCommented:
>>btw how do you make comments in a batch file?

::update the jar with the custom manifest file
jar umf manifest HelloWorld.jar
:: of course the above mean that the manfest file must be called 'manifest'
0
bravotangoAuthor Commented:
Tried that again and still get java.io.FileNotFoundException: manifest (The system cannot find the file specified)
Have to give it away for now as late here. Thanks for help CEHJ
0
CEHJCommented:
You need the file called 'manifest' containing the manifest
0
iXian_Commented:
Here are the steps to make an executable JAR file:

Create a file called "manifest.txt" (not including the quotes).  
The contents of the file should be:

    Main-Class: HelloWordApp

There _must_ be a newline at the end of the file!  
Your .BAT should look like this:

    javac HelloWorldApp.java
    jar cmvf manifest.txt helloworld.jar HelloWorldApp.class

Then you execute with:

    java -jar helloworld.jar
0
bravotangoAuthor Commented:
Had a look at that small Divelog example Objects and had a few minor problems, namely
java.io.FileNotFoundException: mymanifest (The system cannot find the file specified)
Finally stumbled on the omission of the file type suffix
jar cvfm DiveLog.jar mymanifest DiveLog.class DiveLog$1.class DiveLog$2.class Welcome.class
should be
jar cvfm DiveLog.jar mymanifest.mf DiveLog.class DiveLog$1.class DiveLog$2.class Welcome.class

Corrected to mymanifest.mf and it Divelog finally worked.

I then tried this with my helloworldapp and it compiled OK but still have error "Could not find main class".

I then added first line to the manifest.mf for helloworldapp "Manifest-Version: 1.2", similar to the Divelog example but got a duplicate line error.  Real reason for errors here is I was building the jar with
jar cvf HelloWorld.jar HelloWorldApp.java and then updating the manifest with
jar umf mymanifest.mf HelloWorld.jar This doesnt seem to work. It seems better to use
jar cvfm HelloWorld.jar mymanifest.mf HelloWorldApp.class
I did this and it finally worked. I now have a clickable exeutable jar file. It does absolutely nothing but at least it works.

This is really a difficult question to answer (or ask) and as it is now solved I propose dividing the points between CEHJ and Objects if that is OK. Thanks for all the comments.
0
CEHJCommented:
Glad it's working
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.