sri*_*nth 1 maven maven-assembly-plugin
我是maven的新手,它是一门有趣的学科。使用以下命令成功创建具有依赖项的jar:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
现在,我必须包括一些shell脚本和生成的jar到tar中。为此,我尝试了以下方法:已添加
<descriptors>
<descriptor>hadoop-job.xml</descriptor>
</descriptors>
Run Code Online (Sandbox Code Playgroud)
以上脚本。
在hadoop-job.xml中,我将所需文件包含到tar中。
问题是tar首先生成,并说在目标中找不到* .jar。因为这两个配置都位于程序集插件中,所以是否有办法先安排jar创建,然后安排tar。还是有一个命令先执行并生成jar,然后再生成tar命令?
顺便说一句,我正在执行mvn clean assembly:assembly -Dbinary = true。帮我解决。谢谢。
这是一个组装构建具有依赖关系的jar的示例,此后,一个包含此依赖关系jar的tar(由之前的maven-assembly-plugin构建)。在tar中,我还将文件.sh夹中的shell脚本文件包括在内src/main/bin。
首先,插件配置:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorId>jar-with-dependencies</descriptorId>
</descriptorRefs>
</configuration>
</execution>
<execution>
<id>all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/all.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/assembly/</outputDirectory>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
执行的顺序很重要,因为如果我想将jar-with-dependencies包含到我的tar中,则需要先构建它。
我把所有的组件在同一文件夹,这就是为什么我有一个全球性的configuration标签附加到configuration的标签executions
然后是我的汇编文件all.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">
<id>all</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>src/main/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>755</fileMode>
</fileSet>
</fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
这里includeBaseDirectory是为了避免我的tar包含带有项目名称和版本的根文件夹。
如果未指定outputDirectory标签,则归档文件中的文件夹结构将从项目的根目录开始,例如,它将包含jar和path target/your-project-1.0-SNAPSHOT.jar。
编辑:我之前所做的插件配置可以通过以下简化:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorId>jar-with-dependencies</descriptorId>
<descriptors>
<descriptor>src/assembly/all.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/assembly/</outputDirectory>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
究其原因是因为maven-assembly-plugin在descriptorId之前阅读descriptors,这样的好我们的情况,但如果没有,我们就需要为谨慎做高有关订单的两次执行。必须对的顺序进行同样的注意descriptors,它们以阅读顺序执行(这似乎是逻辑,但我认为指出这一点可能很有用)。
| 归档时间: |
|
| 查看次数: |
4376 次 |
| 最近记录: |