0

I get a "no main manifest attribute, in Controller.jar" error when running my Jar file "Controller.jar". Below is my pom.xml file -- what is needed to add the manifest attribute?

Note: I'm aware that similar questions have been asked before, but their solutions do not match my pom configurations, nor do they solve my issues.

//pom.xml:

<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>

    <groupId>com.vismark.rest</groupId>
    <artifactId>Controller</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Controller</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.0.5.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
kramsiv94
  • 641
  • 3
  • 13
  • 31
  • have you tried all of these https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute – Ryuzaki L Nov 06 '18 at 05:32
  • Yes...."Note: I'm aware that similar questions have been asked before, but their solutions do not match my pom configurations, nor do they solve my issues." – kramsiv94 Nov 06 '18 at 16:37

2 Answers2

1

You have to add the following to your pom file:

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
1

As suggested @khmarbaise adding spring bot maven plugin will solve your problem, to explain it:

The Spring Boot Maven Plugin provides Spring Boot support in Maven, letting you package executable jar or war archives and run an application “in-place”. To use it, you must use Maven 3.2 (or later).(see doc build-tool-plugins-maven.

For error there might be couple of reasons:

  1. Either you have not provided "Main class" attribute in Manifest file

  2. You don't have a manifest file in your JAR

If your jar's MANIFEST file doesn't contain "Main Class" than you can not run Java program using command "java -jar name.jar" , it will result in "Failed to load Main manifest attribute from jar". so in your case just add spring boot maven plugin and it will take care of it.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
kj007
  • 6,073
  • 4
  • 29
  • 47