Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No main manifest attribute - IntelliJ

I know there have been many posts on this but I can't seem to find an appropriate solution. So I have my 3 classes, one with a main and from IntelliJ everything runs fine. But I cannot seem to run the .jar file that I have created.

I also have a manifest file that contains the following:

Manifest-Version: 1.0
Main-Class: beanParser

I created the jar through the build option in IntelliJ. Any suggestions?

Thanks

like image 612
joey7492 Avatar asked Jan 16 '15 10:01

joey7492


People also ask

What does no main manifest attribute?

In a Java project, every executable jar file contains a main method. Usually, it is placed at starting point of the application. To execute a main method by a self-executing jar file, we must have a proper manifest file and wrap it with our project at the proper location.

Where is manifest file in IntelliJ?

MF file is located under main/java directory. In such cases Maven doesn't copy it to the output and won't pack into the JAR file, but IDEA incorrectly shows it as actual manifest in the Artifact Editor. In order to solve the problem you just need to move MANIFEST. MF file to main/resources/META-INF directory.

What is main class manifest attribute?

"Main-Class" attribute in MANIFEST. MF file specifies the program entry point or name of Main class, a class that contains the main method in Java. The main method is required to run Java program.


2 Answers

MANIFEST.MF should be in:

src/main/resources/META_INF/

NOT in:

src/main/java/META_INF/

like image 84
Vladislav Avatar answered Oct 20 '22 17:10

Vladislav


Have you considered the following link?

For Maven have a look at the following clip or this one.

Here's a snipped I used in my project:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>your.main.Clazz</mainClass>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/lib/
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
like image 44
Ronald Duck Avatar answered Oct 20 '22 18:10

Ronald Duck