A
A
aye_balbec2022-01-27 16:55:35
Java
aye_balbec, 2022-01-27 16:55:35

How to fix "no main manifest attribute" error?

For some reason I am unable to create an executable jar archive. All the time I run it it comes out "no main manifest attribute".
Here is the source code:

package package1;

public class Dime2{
    public static void main(String [] args){
        try{
            System.out.println("Hello world");
            Thread.sleep(10000);
        } catch(Exception exc){}
    }
}

Here are the commands I entered:
javac package1/Dime2.java
jar cfm dime.jar manifest.txt package1/Dime2.class

And in the manifest.txt file, I wrote only Main-Class: package1.Dime2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2022-01-27
@aye_balbec

Good afternoon!
I can assume problems in the manifest file itself:
There is no line break in the MANIFEST.mf or Manifest.txt file. Because of what it ignores your file. You can verify this if you open the jar with some archiver and look into the directory MANIFEST/MANIFEST.mf
Here, a simple working example:
The structure of directories and files:

folder/package1/Dime2.java
folder/package1/Dime2.class
folder/MANIFEST.mf

Executed commands:
Compile to bytecode
javac Dime2.java
Create an archive
jar cfm dime.jar MANIFEST.mf package1/*.class
Contents of the MANIFEST.mf file (do not forget about line breaks)
Main-Class: package1.Dime2
Contents of the Dime2.jar file
package package1;

public class Dime2{
    public static void main(String [] args){
        try{
            System.out.println("Hello world");
            Thread.sleep(10000);
        } catch(Exception exc){}
    }
}

PS Please note that on some operating systems it is necessary to give permission to run the jar file.
For example, in linux
chmod a+x dime.jar
Well, we run the jar'nick
java -jar dime.jar
PS In the example, I showed MANIFEST.mf, but it doesn't matter. You can also use txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question