Walshy
Walshy

Reputation: 850

No main class in manifest with maven

I have my IntelliJ maven project and I am trying to build the jar but whenever I run it it throws no main manifest attribute, in Project.jar

Here is my pom.xml build. I am trying to set the main class in the manifest with Maven I read online to do it in the maven-compiler-plugin. When I open the jar in WinRar the manifest is generated by Apache Maven but has not got the main class.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>

                    <archive>
                        <manifest>
                            <mainClass>com.bwfcwalshy.ssbbot.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Upvotes: 0

Views: 5144

Answers (1)

egallardo
egallardo

Reputation: 1284

Add the maven-jar-plugin and make sure you use the maven directory structure (src/main/java) for your java files.

...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.bwfcwalshy.ssbbot.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
...

Upvotes: 1

Related Questions