Roam
Roam

Reputation: 4949

create a jar file in the current directory

I am looking to create a jar file in the current directory.

I did this in command line:

jar cfe MyApp.jar MyApp MyApp.class

Alternatively, i put the following into Mnf.txt:

Main-Class: MyApp.class

and ran

jar cfm MyApp.jar Mnf.txt MyApp.class

When i try to run it with

java jar MyApp.jar 

I get the following error in both cases:

Error: could not find or  load main class. 

Mnf.txt & MyApp.class is in the current directory.

There`s no package definition in MyApp. Everything is in the current directory.

I`ve seen How can I convert my Java program to an .exe file? among others.

No idea what i`m missing here.

//===================

ADD:

Changing the content of Mnf.txt to:

Main-Class: MyApp

didn't change anything. i'm getting the same error.

Upvotes: 0

Views: 788

Answers (3)

Ravinder Reddy
Ravinder Reddy

Reputation: 23982

Use

java -jar MyApp.jar

to run the main class in the jar

jar cfe MyApp.jar MyApp MyApp.class
java -jar MyApp.jar

Upvotes: 0

Do not add ".class" to the name of the class in the manifest.

Java differentiates rather strongly between names of files on disk and class names.

Upvotes: 1

m-szalik
m-szalik

Reputation: 3654

There should be manifest entry: Main-Class: MyApp without .class

Upvotes: 0

Related Questions