0

I am trying to create a executable jar with Maven where all the third-party dependency jars are in the root. Included are two pics for examples, and my pom.xml

With this pom, I am getting this result just below it where the jars are broken out into folders.

<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://   /xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany.xmlrpc</groupId>
    <artifactId>gz-xmlrpc-server</artifactId>
    <version>1.1.0-RELEASE</version>
    <packaging>jar</packaging>
    <name>gz-xmlrpc-server</name>
    <url>http://maven.apache.org</url>

    <properties>
        <java-version>1.7</java-version>
        <target-java-version>1.7</target-java-version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.maven.surefire/surefire-junit3 -->
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit3</artifactId>
            <version>3.0.0-M3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.xmlrpc/xmlrpc-server -->
        <dependency>
            <groupId>org.apache.xmlrpc</groupId>
            <artifactId>xmlrpc-server</artifactId>
            <version>3.1.3</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>

        <!-- mycompany -->
        <dependency>
            <groupId>com.mycompany.batch</groupId>
            <artifactId>gz-batch-comptroller</artifactId>
            <version>1.0.0-RELEASE</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.0.0-M2</version>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>3.6.0</version>
                                </requireMavenVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${target-java-version}</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>false</addClasspath>
                            <Main-Class>com.mycompany.xmlrpc.server.Server</Main-Class>
                        </manifest>
                        <manifestEntries>
                            <Built-By>Michael Davidson</Built-By>
                            <Class-Path>.</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>com.mycompany.xmlrpc.server.Server</Main-Class>
                                        <Class-Path>.</Class-Path>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.mycompany.xmlrpc.server.Server</mainClass>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>. gz-batch-comptroller-1.0.0-RELEASE.jar</Class-Path>
                        </manifestEntries>
                    </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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

enter image description here

Here is what I need with the full jars included.

enter image description here

I see other threads on this subject, and I believe my pom is correct. But, I can't seem to get there.

Thanks.

Davidson
  • 1,064
  • 3
  • 20
  • 35

2 Answers2

1

I am not sure why you are using all the 3 maven plugins - jar, shade and assembly.

Could you try using either shade or assembly plugin. You could also refer (if not already) following link to check these plugin usages:

Difference between maven plugins ( assembly-plugins , jar-plugins , shaded-plugins)

Anshul Singhal
  • 1,983
  • 20
  • 25
  • thank you. I removed all by shade. Same result. After looking at the pictures of the two jars, do you know how to get the dependent JARS inside the uber-jar? – Davidson May 13 '19 at 14:43
  • Please use maven-shade-plugin and refer following link which provides example around how to use maven shade plugin - https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html – Anshul Singhal May 13 '19 at 14:59
  • I was using all three from ignorance. – Davidson May 13 '19 at 15:34
  • Please use only maven-shade-plugin (remove maven-jar-plugin and maven-assembly-plugin) and refer already shared link. – Anshul Singhal May 13 '19 at 15:50
  • I resolved it but by not using Maven. I could never get Maven to include the actual jars. So, I used Eclipse Export to Runnable Jar instead. – Davidson May 13 '19 at 16:12
0

Please remove maven-assembly-plugin and maven-jar-plugin completely from pom.xml file and then just use maven-shade-plugin as follows:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Then run mvn clean package and check generated JAR file.

Anshul Singhal
  • 1,983
  • 20
  • 25