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

爷,独闯天下 提交于 2019-12-07 06:04:35

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/25126406/how-to-include-package-jar-with-maven-assembly-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!