I'm trying to create a jar with a main class that's located in one of my two modules. However, the created jar doesn't contain my specified main class.
My project structure is like this MyProject
I make use of the maven-assembly-plugin
to create this jar. The snippet below is located in the project's root pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.MyClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
This creates the jar inside MyProject/target folder. But when inspecting this jar with the jar tvf <file>
command, I only see the Manifest.mf file inside of it. What would be the cause of this class located in first-module not appearing in the jar?
For people in the future: it turns out I needed to use the jar file created in the target folder of the first-module. Before I realised this, I kept using the jar created in the target folder located in the root folder. In the first-module is MyClass
located. And thus the jar from first-module's target folder is able to find and load the specified main class in my root pom.xml.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.