简体   繁体   中英

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!?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM