Home > other >  Java jar file "no main manifest attribute"
Java jar file "no main manifest attribute"

Time:05-08

To start, I have looked at the similar questions posted about this topic. I have not found a solution.

I wish to distribute a small project I have been working on to friends and family. Trouble is I can't expect them all to be able to run .class files. Therefore I am trying to produce a .jar file that I can turn into an .exe file. I am however running into an issue. It complains about missing the main manifest attribute. After some googling, I resolved to try a little tutorial. I am following the tutorial (even downloading the little Hello.jar file), but still I get no main manifest attribute.

As I am running Windows 10, I am using PowerShell to run commands. This is the commands I've run:

PS C:\testJarFraNettet> javac Hello.java
PS C:\testJarFraNettet> jar cmf Hello.mf Hello.jar Hello.class Hello.java
PS C:\testJarFraNettet> java -jar Hello.jar
no main manifest attribute, in Hello.jar
PS C:\testJarFraNettet>

You'll notice I've included the .java file in the .jar as well, just to be sure.

Hello.mf contains:

Manifest-Version: 1.0
Main-Class: Hello

I investigated the .jar file that gets produced. Inside, among the files specified in the command, I find the expected .\META-INF\MANIFEST.MF file with the following content:

Manifest-Version: 1.0
Created-By: 17.0.1 (Eclipse Adoptium)

I've never touched Eclipse (I use VS Code), but I assume this is of no consequence. Per another article I found online, I edited the file to instead contain what the tutorial tells me it should contain:

Manifest-Version: 1.0
Main-Class: Hello

Still no luck. I've decided against showing my own code, as it needlessly complicates troubleshooting since I get the same error anyways. I still have some hurdles left, such as how to add image files. The project is a GUI based game. But that is an issue for later, I suppose.

Thank you for your time!

CodePudding user response:

jar cfe Hello.jar Hello Hello.class Hello.java

will do it for you. You need to point the -e parameter to the main class so that jar knows how to make it executable. This is easier than making your own manifest

  • Related