Maven.在组装项目时如何根据开发版本或生产情况包含特定的文件夹或文件? [英] Maven. How to include specific folder or file when assemblying project depending on is it dev build or production?

查看:87
本文介绍了Maven.在组装项目时如何根据开发版本或生产情况包含特定的文件夹或文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用maven-assembly-plugin

Using maven-assembly-plugin

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1</version>
<configuration>
 <descriptors>
  <descriptor>descriptor.xml</descriptor>
 </descriptors>
 <finalName>xxx-impl-${pom.version}</finalName>
 <outputDirectory>target/assembly</outputDirectory>
 <workDirectory>target/assembly/work</workDirectory>
</configuration>

在descriptor.xml文件中,我们可以指定

in descriptor.xml file we can specify

    <fileSets>
    <fileSet>
        <directory>src/install</directory>
        <outputDirectory>/</outputDirectory>
    </fileSet>
</fileSets>

是否可以根据个人资料在此文件夹或子文件夹中包含特定文件?或其他方式...

Is it possible to include specific file from this folder or sub-folder depending on profile? Or some other way...

喜欢这个:

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <resources>
                <resource>
                    <directory>src/install/dev</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>prod</id>
        <build>
            <resources>
                <resource>
                    <directory>src/install/prod</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </resource>
            </resources>
        </build>
    </profile>
</profiles>

但是在包装时会将资源放在jar中.但是,正如我上面已经提到的,我们在组装时需要将其放在zip中:( 谢谢!

But it puts resources in jar when packaging. But we need to put it in zip when assemblying as I already mentioned above :( Thanks!

推荐答案

如果您的资源具有模式(例如*.properties),则可以在程序集描述符文件中执行以下操作:

If your resources have a pattern (say *.properties) then you can do something like this in your assembly descriptor file:

<fileSets>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.properties</include>
            </includes>
        </fileSet>
</fileSets>

这会将所有*.properties从您的target文件夹复制到程序集zip的根文件夹.根据正在运行的pom.xml中的配置文件,target文件夹中将仅存在适当的资源.

This copies all *.properties from your target folder to the root folder of your assembly zip. Based on the profile in your pom.xml which is being run, only appropriate resources will be present in the target folder.

这篇关于Maven.在组装项目时如何根据开发版本或生产情况包含特定的文件夹或文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆