Maven build assembly with dependencies

gpa :

I have standalone java application, which i wanted to package as: myapp.jar. And all dependent jars to be copied to 'alternate folder'. Ideally, i would like to have maven update META-INF file to add all classpath dependencies jars entries into it.

for example, if my project is referencing commons.jar, and when i use this plugin to build assembly, it copies all .class files and packages from commons.jar into myappjar-with-dependencies.jar.

The problem with maven assembly plugin unjars all dependencies into myappjar-with-dependencies.jar.

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.core.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> 
                    <phase>package</phase> 
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
Evgeniy Dorofeev :

You can try as

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.core.App</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/bin.xml</descriptor>
                </descriptors>
            </configuration>
        </plugin>

src/assembly/bin.xml

<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">
    <formats>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <unpack>false</unpack>
            <includes>
                <include>${artifact}</include>
            </includes>
        </dependencySet>
        <dependencySet>
            <outputDirectory>/lib</outputDirectory>
            <unpack>false</unpack>
            <excludes>
                <exclude>${artifact}</exclude>
            </excludes>
        </dependencySet>
    </dependencySets>
</assembly>

Run it as

mvn clean package assembly:single

Details: http://maven.apache.org/plugins/maven-assembly-plugin/index.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Maven assembly plugin add dependencies

From Dev

Build Maven with Dependencies

From Dev

Build maven assembly in java 8

From Dev

remove all dependencies of a jar within a maven assembly

From Dev

maven build failure - maven dependencies could not be resolved

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 Dev

Eclipse maven build does not install dependencies

From Java

How To: Eclipse Maven install build jar with dependencies

From Dev

How to switch between maven and local build dependencies

From Dev

Maven Build - Couldn't resolve dependencies

From Dev

Maven build dependencies before checking nexus

From Java

Having a maven project build its own dependencies?

From Dev

Maven Dependencies downloaded but build is failing with StackOverflowError

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 Dev

Maven assembly put jar-with-dependencies into tar.gz package

From Dev

Installing MAVEN build dependencies [OSGi bundles] with Maven in to Adobe CQ

From Dev

maven assembly how to add a zip flie from nexus repository to the build

From Java

docker build with maven - how to prevent re-downloading dependencies

From Java

How to build nifi processor nar file and dependencies from maven central

From Java

Maven error POM Manifest Build with Dependencies Java single jar

From Java

Build Path Issue with Maven Dependencies (jconsole-jdk.jar)

From Java

How to add "Maven Managed Dependencies" library in build path eclipse?

From Java

How to configure Eclipse build path to use Maven dependencies?

From Dev

Maven : Build all dependencies but run tests on specific modules

From Dev

'Maven Dependencies' Folder is missing even though build is successful

From Dev

Does "build with local dependencies" exist in Maven without multi-module?

Related Related

  1. 1

    Maven assembly plugin add dependencies

  2. 2

    Build Maven with Dependencies

  3. 3

    Build maven assembly in java 8

  4. 4

    remove all dependencies of a jar within a maven assembly

  5. 5

    maven build failure - maven dependencies could not be resolved

  6. 6

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

  7. 7

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

  8. 8

    Eclipse maven build does not install dependencies

  9. 9

    How To: Eclipse Maven install build jar with dependencies

  10. 10

    How to switch between maven and local build dependencies

  11. 11

    Maven Build - Couldn't resolve dependencies

  12. 12

    Maven build dependencies before checking nexus

  13. 13

    Having a maven project build its own dependencies?

  14. 14

    Maven Dependencies downloaded but build is failing with StackOverflowError

  15. 15

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

  16. 16

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

  17. 17

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

  18. 18

    Maven assembly put jar-with-dependencies into tar.gz package

  19. 19

    Installing MAVEN build dependencies [OSGi bundles] with Maven in to Adobe CQ

  20. 20

    maven assembly how to add a zip flie from nexus repository to the build

  21. 21

    docker build with maven - how to prevent re-downloading dependencies

  22. 22

    How to build nifi processor nar file and dependencies from maven central

  23. 23

    Maven error POM Manifest Build with Dependencies Java single jar

  24. 24

    Build Path Issue with Maven Dependencies (jconsole-jdk.jar)

  25. 25

    How to add "Maven Managed Dependencies" library in build path eclipse?

  26. 26

    How to configure Eclipse build path to use Maven dependencies?

  27. 27

    Maven : Build all dependencies but run tests on specific modules

  28. 28

    'Maven Dependencies' Folder is missing even though build is successful

  29. 29

    Does "build with local dependencies" exist in Maven without multi-module?

HotTag

Archive