Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

java - Changing packaging based on active profile in pom

I have a project which I compile with maven. I have different profiles declared in pom.xml. For some of these profiles, I prefer building a war, and for other profiles I prefer a jar. I use to manually edit the pom.xml file and change packaging variable to either

<packaging>war</packaging>

or

<packaging>jar</packaging>

before doing a

$ mvn clean package -Pchosenprofile

How can I tell mvn the packaging corresponding to each profile so I don't need to edit pom.xml?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to use profile you can use something like:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    ..
    <packaging>${packaging.type}</packaging>

    <profiles>
        <profile>
            <id>webapp</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <packaging.type>war</packaging.type>
            </properties>
        </profile>
        <profile>
            <id>batch</id>
            <properties>
                <packaging.type>jar</packaging.type>
            </properties>
                </profile>
          </profiles>
</project>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...