1

I have a multi-module Maven project from which I would like to create executable jar. Below you can see the expansion of my project:

main-module
    |___basis-service
    |       |___src/main/java
    |       |
    |       |___src/main/resources
    |       |
    |       |___src/test/java
    |       |
    |       |___src/test/resources
    |
    |___controller-service
            |___src/main/java
            |       |___de.app2
            |              |___App2BasisServiceApplication
            |
            |___src/main/resources
            |
            |___src/test/java
            |       |___de.app2
            |              |___App2BasisServiceApplicationTest
            |
            |___src/test/resources

The path of the main de.app2.App2BasisServiceApplication. And here is my Parent.pom

             <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <mainClass>de.app2.App2BasisServiceApplication</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
            </plugin>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>${maven.assembly.plugin.version}</version>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>de.app2.App2BasisServiceApplication</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>

From this stackoverflow question I got my information how to create an executable jar: How to build an executable jar from multi module maven project?

When I build my application then I get a jar, but this jar doesn't seem to have any of my classes. When I look at the jar in a decompiler then I don't see my classes there either.

What the Decompiler shows: enter image description here

Also when I try to run my jar in the console with java -jar appname.jar then I get the error: Could not find or load main class .

Does anyone know what I am doing wrong and how I can solve the problem?

Thanks in advance

Doncarlito87
  • 359
  • 1
  • 8
  • 25

1 Answers1

0

spring-boot-maven-plugin should do everything what you need.

Please remove maven-assembly-plugin from your configuration.

Slawomir Jaranowski
  • 7,381
  • 3
  • 25
  • 33
  • thank you for your answer. I have removed maven-assembly-plugin. Now I have a jar that shows all my classes. But this jar is only 226 kb in size. This seems a little small to me. I have about 300 classes in it. Is this a reason to worry? And when i want to run the jar via the cmd then i get the error "java : no main manifest attribute". – Doncarlito87 Oct 26 '22 at 18:34
  • I just noticed that the classes from the base service that are loaded as dependency into the controller service are also missing. – Doncarlito87 Oct 26 '22 at 18:48