简体   繁体   中英

Unable to generate a single jar file with dependencies in maven

Requirement: Generate a single jar file with dependencies and give a cutsom name to the jar file.

My problem is I only need to generate a single jar file with dependencies, I don't need the default generated jar file. When I 'mvn clean install' I get the result with two jar files of names: FPMWebDocumentation-0.0.1.jar, FPMWebDocu.jar

I don't want the FPMWebDocumentation-0.0.1.jar file to be generated, I need only FPMWebDocu.jar to be generated. If I remove the groupId, artifactId, version outside of the build node it gives the error of 'groupId' missing, 'artifactId' missing and so on. Now if I remove groupId & version from it's current location and put inside inside the plugin node, it still gives same missing error as above.

Below is my pom.xml:

<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>

<groupId>com.fraunhofer.latexDocumentation</groupId>
<artifactId>FPMWebDocumentation</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>

<name>FPMWebDocumentation</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>com.fraunhofer.latexDocumentation.MainClass</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <finalName>FPMWebDocu</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.8.3</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
</dependencies>
</project>

If there is no special concern, just leave FPMWebDocumentation-0.0.1.jar there. That file is actually the main artifact of the project itself. Your FPMWebDocu.jar is actually the "extra" JAR being generated.

Please let us know what is your concern of having the main artifact there, for which may be able to solve by other solution


If I remember correctly, default behavior of maven-shade-plugin is to use the shaded JAR as the main artifact of the project. Take a look here to see how to make an uber JAR by shade plugin

(However, it is usually a bad idea to make an uber-jar as main artifact, as it is going to ruin dependency management mechanism if you use the uber-jar as dependency)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM