I have a project which has multiple .jar files in it. To add this as a dependency, I need to turn all these jars into one big jar. So far I have come until:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>mainProjects</groupId>
<artifactId>mainProjects.master</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>mainProjects</groupId>
<artifactId>sampleModule1</artifactId>
<name>sampleModule1</name>
<version>1.0.0.qualifier</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>Sample1.jar</include>
<include>Sample2.jar</include>
</includes>
</artifactSet>
<finalName>${project.artifactId}-${project.version}-final</finalName>
<outputDirectory>${project.artifactId}/build</outputDirectory>
<shadedArtifactAttached>false</shadedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This creates the final jar, however, inside there are no content from the other jars (sample1.jar and sample2.jar) as there should be. I have looked into the documentation of the plugin, however all they did was to do it via class files, not jars. So I don't know how to proceed from now on.
Any thoughts?
Update:
So in order to make it clear, hereby I share the project structure that I have:
+- mainProjects
| +- pom.xml
| +- mainProject1
| | +- pom.xml
| | +- src
| +- mainProject2
| | +- pom.xml
| | +- src
| +- group1
| | +- pom.xml
| | +- sampleModule1
| | | +- pom.xml
| | | +- build
| | | +- sample1.jar
| | | +- sample2.jar
| | | +- sample3.jar
| | | +- sample4.jar
| | | +- sample5.jar
| | | +- sample6.jar
| | +- sampleModule2
| | | +- pom.xml
| | | +- src
Now, I want to be able to use sampleModule1
as a dependency in the pom.xml
of mainProject1
as a jar, like this:
<dependency>
<groupId>group1</groupId>
<artifactId>sampleModule1</artifactId>
<version>1.0.0.qualifier</version>
<scope>system</scope>
<systemPath>sampleModule1/build/${project.artifactId}-${project.version}-final.jar</systemPath>
</dependency>
to achieve this, I need to compile all the jars into one jar, so that I can add it by using one systemPath
. I found this which shows an example of how to include multiple files into one. However, in the example they are not jars, but rather classes and others. Now here, I am trying to achieve the same, but with only jars.