【问题标题】:Maven assembly plugin - complex zipping scriptMaven 组装插件 - 复杂的压缩脚本
【发布时间】:2013-07-05 19:45:27
【问题描述】:

我有下一个目录结构:

src/main/resources/export/v1/android/ src/main/resources/export/v1/ios/ src/main/resources/export/v2/android/ src/main/resources/export/v2/ios/ ... src/main/resources/export/vn/android/ src/main/resources/export/vn/ios/

我需要得到下一个结果:

WEB-INF/export/v1/android.zip WEB-INF/export/v1/ios.zip WEB-INF/export/v2/android.zip WEB-INF/export/v2/ios.zip ... WEB-INF/export/vn/android.zip WEB-INF/export/vn/ios.zip

我可以用 maven-assembly-plugin 解决问题吗?如果没有,是否有另一个插件可以处理它或者编写自定义类并使用 exec-maven-plugin 调用它更好?

【问题讨论】:

  • 是的,你可以用汇编插件解决这个问题。
  • 也许我还没有完全表达我的问题——我希望能够添加新版本的资源(android、ios)而无需添加新的编辑 pom.xml 的程序集文件

标签: java maven maven-assembly-plugin


【解决方案1】:

这是我通过修补插件得出的结论。我已经能够创建一个包含一些任意文件的 zip。这是我定义的插件:

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptors>
                    <descriptor>src/main/resources/my-assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>assembly-id</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这里是 my-assembly.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>zip-example</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>src/main/java/com/sandbox</directory>
        </fileSet>
    </fileSets>

</assembly>

希望有一种更简单的方法可以满足您的需求,但是从这一点开始,您可以为需要构建的每个 zip 创建一个程序集文件,这对您有用。

【讨论】:

  • 感谢您的回答,但这并不能解决我的问题。我已经设法用一个程序集文件创建了一个 zip,但我的目标是能够添加新版本而无需添加新程序集或编辑 pom.xml
  • @polarfish 好的,这可能是可能的,但你有点含糊。你能更具体地说明未来会发生什么吗?可以编辑汇编文件吗?
【解决方案2】:

我最终编写了 java 类并使用 exec-maven-plugin 运行它,如下所示:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
        <id>Running custom java class</id>
        <phase>compile</phase>
        <goals><goal>java</goal></goals>
        <inherited>false</inherited>
        <configuration>
            <mainClass>mycompany.CustomJavaClass</mainClass>
            <classpathScope>compile</classpathScope>
            <arguments>
                <argument>
                  ${project.basedir}/src/main/resources/export
                </argument>
                <argument>
                  ${project.basedir}/target/art-1.0/WEB-INF/export
                </argument>
            </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多