【问题标题】:POM that zips the project压缩项目的 POM
【发布时间】:2012-11-08 00:35:52
【问题描述】:

是否可以创建一个 POM,在打包或更高版本中,仅将整个项目组合起来(例如,压缩到一个 zip 文件中)并将其放置在目标中?

在这种情况下,项目中没有任何 Java 代码,它只是一组我想要打包的脚本和文件。为了统一起见(因为我们的商店都是 Maven),我真的很想有一个 POM 来做这件事,因为目前,我们有一个 shell 脚本来做这件事。

示例将不胜感激。

谢谢

【问题讨论】:

  • 是的,不过,这比我要找的要复杂一些。我即将发布我自己想出的东西(很好也很简单)。不过感谢您的帮助:)

标签: java maven


【解决方案1】:

所以我最终得到了以下内容,它在target 中创建了一个文件ServerSetupTools-0.1-SNAPSHOT.tar.gz,这对我有用。唯一的缺点是我不确定如何让它在根目录中提取文件,所以我将它们全部移动到src/main/resources,这对我也有用。希望这对其他人有帮助。

POM 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>ServerSetupTools</artifactId>
<packaging>pom</packaging>
<name>ServerSetupTools</name>
<url>http://maven.apache.org</url>
<groupId>com.mycompany.utilities</groupId>
<version>0.1-SNAPSHOT</version>
<build>
    <plugins>
        <!--  Run assembly as part of packaging -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>
                        src/main/assembly/assemble.xml
                    </descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase><!-- append to the packaging phase. -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

src/main/assembly/assemble.xml

<assembly xmlns="http://maven.apache.org/xsd/assembly"
xsi:schemaLocation="http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>dist</id>
<formats>
    <format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
    <fileSet>
        <includes>
            <include>*</include>
        </includes>
        <directory>src/main/resources</directory>
        <outputDirectory>bin</outputDirectory>
        <fileMode>0755</fileMode>
    </fileSet>
</fileSets>     

【讨论】:

  • 你应该坚持Maven Standard Directory Layout。这意味着您的脚本应该在src/main/scripts 而不是src/main/resources。而且你不应该使用maven-assembly-plugin 的测试版,使用最新的2.3 版本。
  • 这很好。不幸的是,这个项目中包含的文件并不是所有的脚本(里面有一些 jars 等等)。为了简单起见(以牺牲组织为代价),我将坚持使用resources。根据您的建议,我将切换到 2.3
猜你喜欢
  • 2015-11-28
  • 2019-12-09
  • 2020-02-15
  • 1970-01-01
  • 2018-03-05
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 2016-09-26
相关资源
最近更新 更多