I have created a multi-module maven application where there are 2 modules. The first module plays the role of a library, the second module has the main method. I want to get the assembly of the exe file from the launching (second) module and the lib folder where only the jar file from the first module is located with the dependencies inside. I tried using the following pom. xml (in the launcher), but it puts the library in the jar, which is not what I would like. What needs to be fixed?
<dependencies>
<dependency>
<groupId>com.XXX</groupId>
<artifactId>first_module</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>XXX.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>2.1.3</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<stayAlive>true</stayAlive>
<outfile>XXX.exe</outfile>
<jar>${project.build.directory}/${project.artifactId}-${project.version}-jar-with-dependencies.jar</jar>
<errTitle>encc</errTitle>
<classPath>
<mainClass>XXX.Main</mainClass>
<addDependencies>true</addDependencies>
<preCp>anything</preCp>
</classPath>
<jre>
<path>runtime</path>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>XXX</fileDescription>
<copyright>XXX</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>${project.version}</txtProductVersion>
<productName>XXX</productName>
<originalFilename>XXX.exe</originalFilename>
<internalName>XXX</internalName>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I solved it by adding maven-shade-plugin to the first module to combine all the dependencies. You can also use maven-assembly-plugin.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
then I added the maven-dependency-plugin in launch (second) module which copies the shaded-jar from the first module to the target/lib folder
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>
I also added "maven-jar-plugin" to build launch (second) module jar-file after "maven-dependency-plugin" with instructions "classpathPrefix" where is first module.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>XXX.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
At the end I added "launch4j-maven-plugin" which packed my jar into an exe file.
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>2.1.3</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<stayAlive>false</stayAlive>
<outfile>${project.build.directory}/XXX.exe</outfile>
<chdir>.</chdir>
<jar>${project.build.directory}/${project.artifactId}-${project.version}.jar</jar>
<errTitle>encc</errTitle>
<jre>
<path>runtime</path>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>XXX</fileDescription>
<copyright>XXX</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>${project.version</txtProductVersion>
<productName>XXX</productName>
<originalFilename>XXX.exe</originalFilename>
<internalName>XXX</internalName>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>