0

I am working on a project using spring-boot. I have my own parent .pom file, so I can't use the spring-boot parent pom. When I package the project, the main class is not being included in the MANIFEST.MF, even though I specify it in the plug-in configuration. So when I try to run the jar, java says it can't find the main class.

no main manifest attribute, in processor-interface-1.0.0.jar

<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>tld.domain.system</groupId>
<artifactId>processor-interface</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>

<parent>
    <groupId>tld.domain.maven</groupId>
    <artifactId>super-pom</artifactId>
    <version>[0.1,1.0)</version>
</parent>

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <log4j.version>2.9.1</log4j.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.6.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.6.RELEASE</version>
            <configuration>
                <mainClass>tld.domain.system.boot.ProcessorInterface</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

I have drilled into the MANIFEST.MF in the .jar file and there is indeed no main-class: line. How do I specify the main class in the pom so that it is included in the MANIFEST.MF?

bcr666
  • 2,157
  • 1
  • 12
  • 23

2 Answers2

1

I have similar setup and the only difference with you is that my spring-boot-maven-plugin execution is tied to repackage phase:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>my main class</mainClass>
                </configuration>
            </plugin>
tsolakp
  • 5,858
  • 1
  • 22
  • 28
  • I'm not sure why this worked, and why it wasn't in the other documentation that I've seen. But it appears to work, thanks. – bcr666 Nov 24 '17 at 18:11
  • Without specifying the execution phase maven wont run the plugin. Here is same setup from Spring docs: https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html – tsolakp Nov 24 '17 at 18:14
0

This was not enough approach for us to achieve above requirement...(As somehow spring-boot-maven-plugin was not working in our case).

However I had to complete my mvn command by appending spring-boot:repackage and

<properties>
        <start-class>fully qualified name of the main class</start-class>
    </properties>