Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include package.jar with maven-assembly-plugin

I used maven and maven-jar-plugin and maven-assembly-plugin to build a zip of my project including the projects jar and its dependencies.

This is the plugin configuration:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>MyMainClass</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptors>
                    <descriptor>src/main/assembly/assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

And this is the assembly.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <includes>${project.build.finalName}</includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/lib/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>

I try to include the jar created by the maven-jar-plugin using <fileSet><includes>${project.build.finalName}</includes>.... But this throws an error:

Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (default) on project tbdb-core: Error reading assemblies: Error reading descriptor: src/main/assembly/assembly.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<fileSet>\r\n\t\t\t<includes>${project.build.finalName}</... @10:42) -> [Help 1]

Omitting the fileset entry, I get an zip only with the dependencies.

How can I include just the jar created by the maven-jar-plugin? TIA!

like image 992
t777 Avatar asked Aug 04 '14 19:08

t777


1 Answers

try this:

<fileSet>
      <directory>${project.build.directory}</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet>

Please refer to Guide to creating assemblies for more details.

like image 53
user3487063 Avatar answered Oct 09 '22 07:10

user3487063