Maven assembly plugin add dependencies

Spring

I have a java application and using maven-assembly-plugin I want to add my dependencies to a /lib folder in my release.

In a web project its simple because jars are already in the war file. I coudln't figure out to do it in standart java application since all external jars are in my local .m2 repository.

Seelenvirtuose

I often work with this assembly configuration

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <id>assembly</id>

    <formats>
        <format>zip</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
            <outputFileNameMapping>${artifact.groupId}.${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
            <useProjectArtifact>false</useProjectArtifact>
            <!-- you may place excludes here -->
        </dependencySet>
    </dependencySets>

    <files>
        <file>
            <outputDirectory>/</outputDirectory>
            <source>${project.build.directory}/${project.artifactId}-${project.version}.jar</source>
            <destName>${project.artifactId}.jar</destName>
        </file>
    </files>

    <fileSets>
        <fileSet>
            <outputDirectory>config</outputDirectory>
            <directory>config</directory>
        </fileSet>
        <fileSet>
            <outputDirectory>/</outputDirectory>
            <directory>src/main/bin</directory>
        </fileSet>
    </fileSets>

</assembly>

And then I reference it in my POM with

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>create-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>assembly/assembly.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
</plugin>

If you also need a runnable JAR:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
            <manifestEntries>
                <Class-Path>config/</Class-Path>
            </manifestEntries>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <classpathLayoutType>custom</classpathLayoutType>
                <customClasspathLayout>$${artifact.groupId}.$${artifact.artifactId}.$${artifact.extension}</customClasspathLayout>
            </manifest>
        </archive>
    </configuration>
</plugin>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to exclude dependencies from maven assembly plugin : jar-with-dependencies?

From Dev

Maven assembly plugin: how to include provided dependencies of transitive dependencies

From Java

Maven assembly plugin not producing jar-with-dependencies any more, why?

From Java

Include Maven profile name in assembly-plugin built (with dependencies) jar

From Dev

How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

From Java

Maven build assembly with dependencies

From Java

Is there a way to add maven dependencies while using the maven-jlink-plugin?

From Dev

Maven Assembly Plugin NoClassDefFoundError

From Dev

Is the content of the Maven Assesmnly plugin's jar-with-dependencies descriptorRef documented as an example assembly descriptor file anywhere?

From Dev

Using maven assembly plugin to create ZIP file containing a fat jar (jar-with-dependencies)

From Dev

Maven add WorldEdit Dependencies

From Dev

Maven add dependencies to project

From Dev

Maven Assembly Plugin Merge Strategy

From Dev

Maven shade plugin - Jar and dependencies

From Java

Maven plugin to output class dependencies

From Java

Maven dependency management for plugin dependencies

From Dev

Convert Maven `maven-assembly-plugin` to Gradle

From Dev

remove all dependencies of a jar within a maven assembly

From Dev

How to add files from webapp directory to jar using Maven Assembly plugin?

From Java

How do I add an Implementation-Version value to a jar manifest using Maven's assembly plugin?

From Dev

Execution order of maven-assembly-plugin and maven-jar-plugin

From Java

Maven: Add local dependencies to jar

From Dev

Execute maven assembly plugin only on child POMs

From Dev

maven-assembly-plugin: Excluding files

From Dev

Intellij Idea ignores maven assembly plugin

From Java

maven-assembly-plugin: How to use appendAssemblyId

From Dev

Switching "maven-assembly-plugin" on/off

From Dev

Detecting missing included file with Maven assembly plugin

From Java

How make parameters necessary in Maven Assembly Plugin

Related Related

  1. 1

    How to exclude dependencies from maven assembly plugin : jar-with-dependencies?

  2. 2

    Maven assembly plugin: how to include provided dependencies of transitive dependencies

  3. 3

    Maven assembly plugin not producing jar-with-dependencies any more, why?

  4. 4

    Include Maven profile name in assembly-plugin built (with dependencies) jar

  5. 5

    How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

  6. 6

    Maven build assembly with dependencies

  7. 7

    Is there a way to add maven dependencies while using the maven-jlink-plugin?

  8. 8

    Maven Assembly Plugin NoClassDefFoundError

  9. 9

    Is the content of the Maven Assesmnly plugin's jar-with-dependencies descriptorRef documented as an example assembly descriptor file anywhere?

  10. 10

    Using maven assembly plugin to create ZIP file containing a fat jar (jar-with-dependencies)

  11. 11

    Maven add WorldEdit Dependencies

  12. 12

    Maven add dependencies to project

  13. 13

    Maven Assembly Plugin Merge Strategy

  14. 14

    Maven shade plugin - Jar and dependencies

  15. 15

    Maven plugin to output class dependencies

  16. 16

    Maven dependency management for plugin dependencies

  17. 17

    Convert Maven `maven-assembly-plugin` to Gradle

  18. 18

    remove all dependencies of a jar within a maven assembly

  19. 19

    How to add files from webapp directory to jar using Maven Assembly plugin?

  20. 20

    How do I add an Implementation-Version value to a jar manifest using Maven's assembly plugin?

  21. 21

    Execution order of maven-assembly-plugin and maven-jar-plugin

  22. 22

    Maven: Add local dependencies to jar

  23. 23

    Execute maven assembly plugin only on child POMs

  24. 24

    maven-assembly-plugin: Excluding files

  25. 25

    Intellij Idea ignores maven assembly plugin

  26. 26

    maven-assembly-plugin: How to use appendAssemblyId

  27. 27

    Switching "maven-assembly-plugin" on/off

  28. 28

    Detecting missing included file with Maven assembly plugin

  29. 29

    How make parameters necessary in Maven Assembly Plugin

HotTag

Archive