0

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>
Walshy
  • 850
  • 2
  • 11
  • 32
  • 2
    I'm fairly sure the compiler plugin can't do this (it compiles your code, doesn't produce the jar). You need to specify it in whatever packages your jar, probably maven-jar-plugin. See https://maven.apache.org/shared/maven-archiver/examples/classpath.html – matt freake Sep 05 '16 at 16:55
  • 4
    Possible duplicate of [Can't execute jar- file: "no main manifest attribute"](http://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute) – Tunaki Sep 05 '16 at 17:15

1 Answers1

1

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>
...
egallardo
  • 1,234
  • 1
  • 15
  • 25