Maven AntRun 插件包含 tar 上的根文件夹
Maven AntRun plugin include root folder on tar
在我的项目中,我需要创建一个包含文件夹全部内容的 tar。
我使用 maven antRun 插件来完成。
我的问题是主根不在 tar 中。
如何插入文件夹?
Es。
我有
Target
---temp
---Example
------aaa.png
------bbbb.png
------rsc
---------ccc.png
我是我的file.tar.gz我有
aaa.png
bbbb.png
rsc
---ccc.png
我想要
---Example
------aaa.png
------bbbb.png
------rsc
---------ccc.png
创建 tar
的代码
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>tar batch</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="tar.gz folder">
<echo message="Starting to compress with tar.gz ${main.builddir}${file.separator}${tar.name.batch} in ${main.builddir}${file.separator}${tar.name.batch}.tar.gz " />
<tar destfile="${main.builddir}${file.separator}${tar.name.batch}.tar" basedir="${main.builddir}${file.separator}${tar.name.batch}" />
<gzip destfile="${project.build.directory}${file.separator}${tar.name.batch}.tar.gz" src="${main.builddir}${file.separator}${tar.name.batch}.tar" />
</target>
</configuration>
</execution>
</executions>
</plugin>
我建议使用 maven-assembly-plugin 而不是 maven-antrun-plugin。您需要在您的 pom 文件中进行这样的配置:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-archives</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
此外,您需要有一个 assembly descriptor which describes 应该像这样打包到存档中的内容:
<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>dist-assembly</id>
<formats>
<format>tar</format>
</formats>
<!--
! The following will include the base directory incl. version
! into the resulting tar.
! The default value is: true.
! <includeBaseDirectory>true</includeBaseDirectory>
-->
<fileSets>
<fileSet>
<directory>folder</directory>
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
</assembly>
要控制存档中的文件夹,您可以使用 outputDirectory
。 directory
控制应将哪个文件夹打包到存档中。
这不是最干净的解决方案,但我解决了添加另一个子文件夹的问题,
所以当我生成 jar 时,我把它放在 executable/executable 中,然后在我创建第一个可执行文件文件夹的 tar.gz 之后。
在我的项目中,我需要创建一个包含文件夹全部内容的 tar。 我使用 maven antRun 插件来完成。 我的问题是主根不在 tar 中。 如何插入文件夹?
Es。 我有
Target
---temp
---Example
------aaa.png
------bbbb.png
------rsc
---------ccc.png
我是我的file.tar.gz我有
aaa.png
bbbb.png
rsc
---ccc.png
我想要
---Example
------aaa.png
------bbbb.png
------rsc
---------ccc.png
创建 tar
的代码 <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>tar batch</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="tar.gz folder">
<echo message="Starting to compress with tar.gz ${main.builddir}${file.separator}${tar.name.batch} in ${main.builddir}${file.separator}${tar.name.batch}.tar.gz " />
<tar destfile="${main.builddir}${file.separator}${tar.name.batch}.tar" basedir="${main.builddir}${file.separator}${tar.name.batch}" />
<gzip destfile="${project.build.directory}${file.separator}${tar.name.batch}.tar.gz" src="${main.builddir}${file.separator}${tar.name.batch}.tar" />
</target>
</configuration>
</execution>
</executions>
</plugin>
我建议使用 maven-assembly-plugin 而不是 maven-antrun-plugin。您需要在您的 pom 文件中进行这样的配置:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-archives</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
此外,您需要有一个 assembly descriptor which describes 应该像这样打包到存档中的内容:
<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>dist-assembly</id>
<formats>
<format>tar</format>
</formats>
<!--
! The following will include the base directory incl. version
! into the resulting tar.
! The default value is: true.
! <includeBaseDirectory>true</includeBaseDirectory>
-->
<fileSets>
<fileSet>
<directory>folder</directory>
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
</assembly>
要控制存档中的文件夹,您可以使用 outputDirectory
。 directory
控制应将哪个文件夹打包到存档中。
这不是最干净的解决方案,但我解决了添加另一个子文件夹的问题, 所以当我生成 jar 时,我把它放在 executable/executable 中,然后在我创建第一个可执行文件文件夹的 tar.gz 之后。