1

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>
Subash Basnet
  • 307
  • 1
  • 4
  • 15

1 Answers1

0

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)

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • Adrian Shum I couldn't make the question clear to you, I've edited it, now it should be more clear, thanks. – Subash Basnet Sep 08 '15 at 07:38
  • You update makes no difference: `FPMWebDocumentation-0.0.1.jar` is not only the "default" being generated, it is the main artifact of the project. The `FPMWebDocu.jar` is simply an extra JAR generated by assembly plugin. What is the problem to you to have the main artifact there? Tell us your actual problem and let's suggest solution for you – Adrian Shum Sep 08 '15 at 07:57
  • There are ugly hacks like http://stackoverflow.com/questions/2188746/what-is-the-best-way-to-avoid-maven-jar but I don't see it worth to make such unmaintainable POM like this without strong reasons – Adrian Shum Sep 08 '15 at 08:00
  • It's in the requirement, I need to generate a jar file with dependencies that has a custom name, if default jar file includes dependencies and has a custom name, that would be great. And If that's not possible in default jar, then I need only the extra JAR to be generated. – Subash Basnet Sep 08 '15 at 08:16
  • What it does now already fit your requirement: it DOES generate an uber-jar with custom name. At least base on what I can understand, the requirement is not asking you to ONLY generate 1 and only 1 uber-jar. If 2 JARs in same directory makes you uncomfortable, just put the uber-jar in another directory, like `target/uber-jar` – Adrian Shum Sep 08 '15 at 08:22
  • Btw, iirc, shade plugin provides a way to replace the main artifact with the shaded JAR. You can take a look (Though it is usually a bad idea to use uber jar as main artifact for a project) – Adrian Shum Sep 08 '15 at 08:26
  • Hehe, with 'a jar file' I meant single jar file, yeah I could put that in another directory as you said, but if main jar file had all dependencies has a custom name, I would not need to generate another extra jar. – Subash Basnet Sep 08 '15 at 08:39
  • Again, that's not the extra file. That one is actually the main artifact. The uber-jar is the extra being generated. Anyway, just check shade plugin, it should work for you. However I don't fine the requirement being a sane one :P – Adrian Shum Sep 08 '15 at 08:46