Brendan Hill
Brendan Hill

Reputation: 3752

Using jar.exe with manifest file for executable - "no main manifest attribute"

I have scoured Google and StackOverflow for a resolution and found none so far. I am trying to produce a simple executable .jar package using a manifest file from the Windows command line using Java 1.8. The relevant files are:

Turtlephilia.java:

public class Turtlephilia {
    public static void main(String[] args) {
        System.out.println("i lurrrve turtles");
    }
}

manifest.mf:

Main-Class: Turtlephilia

do.bat:

javac Turtlephilia.java

jar cvmf manifest.mf Turtlephilia.jar Turtlephilia.class 

java -jar Turtlephilia.jar

When I execute do.bat it compiles and archives successfully, but upon running the jar file, it generates this error:

no main manifest attribute, in Turtlephilia.jar

NOTE: I am actually able to successfully run it with this command:

java -cp Turtlephilia.jar Turtlephilia

But I need it to be an executable jar.

What am I doing wrong? How hard can it be!?

Upvotes: 1

Views: 805

Answers (1)

Brendan Hill
Brendan Hill

Reputation: 3752

Well I found the reason.

I had created the manifest.mf file in Notepad and had a single line for Main-Class.

Turns out that it needs a carriage return after this line to recognize it ie. a blank line at the end.

Having been banging my head against the wall for several hours of this I am not enthralled by the Java development environment.

Upvotes: 2

Related Questions