开发者

Use one pom.xml for different projects

I use maven to build my java based program. It is work fine. But now I meet an is开发者_JAVA技巧sue which request me to build a revision for other users which is based on the same source code with a little different(e.g. different software name, and different resource file).

Does anyone have any idea about how to do it?


You need to use profiles. It's a little complicated to explain in an answer like this, but essentially, you will create different profiles within your POM for the different builds you want to do. You will choose the profile at build time, using, e.g., a variable definition in the mvn command line, and within the profile, you change any of the variables or settings that you need to change. Lots more info is available here.


Depending on the type of project, the most "maven" way to do this would be to split up the project into a parent with multiple children. Your main project is put into one module and each of user specific configurations goes into a different module, which can then depend on the common code.

Each of the user specific modules can have their own resources and unique configuration, which would make producing different named configurations easier. It would also make any user specific coding tweaks easier.


You can create different profiles within your POM for the different builds you want to do.

Here are some of the example part of POM.xml

<!-- Define profiles here and make DEV as default profile -->
<profiles>

    <!-- dev Profile -->
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

    <!-- qa Profile -->
    <profile>
        <id>qa</id>
        <properties>
            <env>qa</env>
        </properties>
    </profile>

    <!-- prod Profile -->
    <profile>
        <id>prod</id>
        <properties>
            <env>prod</env>
        </properties>
    </profile>

</profiles>
...


<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4.3</version>

    <executions>
        <execution>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜