问题描述
我使用maven和maven-jar-plugin和maven-assembly-plugin构建了我的项目的zip文件,包括项目jar及其依赖项.
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.
这是插件配置:
<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>
这是assembly.xml:
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>
我尝试使用<fileSet><includes>${project.build.finalName}</includes>...
包含由maven-jar-plugin创建的jar.但这会引发错误:
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]
省略fileset
条目,仅获得包含依赖项的zip.
Omitting the fileset
entry, I get an zip only with the dependencies.
如何仅包含由maven-jar-plugin创建的jar? TIA!
How can I include just the jar created by the maven-jar-plugin? TIA!
推荐答案
尝试一下:
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
有关更多详细信息,请参考创建程序集的指南.
Please refer to Guide to creating assemblies for more details.
这篇关于如何在Maven-assembly-plugin中包含package.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!