maven切换环境配置

来源:互联网 发布:php base64 编辑:程序博客网 时间:2024/06/05 16:17

maven结构 


父级pom代码

<groupId>com.minifast</groupId><artifactId>minifast</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><name>minifast</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><span style="white-space:pre"></span><dependencies><span style="white-space:pre"></span><dependency><span style="white-space:pre"></span>  <groupId>javax.servlet</groupId><span style="white-space:pre"></span>  <artifactId>javax.servlet-api</artifactId><span style="white-space:pre"></span>  <version>3.0.1</version><span style="white-space:pre"></span></dependency><span style="white-space:pre"></span></dependencies><modules><module>minifast-biz</module><module>minifast-common</module><module>minifast-web</module></modules>

biz pom代码
<parent>    <groupId>com.minifast</groupId>    <artifactId>minifast</artifactId>    <version>0.0.1-SNAPSHOT</version>  </parent>  <artifactId>minifast-biz</artifactId>  <packaging>jar</packaging>  <name>minifast-biz</name>  <url>http://maven.apache.org</url> <dependencies>     <dependency>      <groupId>com.minifast</groupId>      <artifactId>minifast-common</artifactId>      <version>${project.version}</version>    </dependency>  </dependencies>

common pom 代码

       <parent>        <groupId>com.minifast</groupId><artifactId>minifast</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>minifast-common</artifactId><packaging>jar</packaging><name>minifast-common</name><url>http://maven.apache.org</url>
web pom 代码

<parent>    <groupId>com.minifast</groupId>    <artifactId>minifast</artifactId>    <version>0.0.1-SNAPSHOT</version>  </parent>  <artifactId>minifast-web</artifactId>  <packaging>war</packaging>  <name>minifast-web</name>  <url>http://maven.apache.org</url>  <dependencies>     <dependency>      <groupId>com.minifast</groupId>      <artifactId>minifast-config</artifactId>      <version>${project.version}</version>      </dependency>      <dependency>      <groupId>com.minifast</groupId>      <artifactId>minifast-biz</artifactId>      <version>${project.version}</version>      </dependency>  </dependencies>  <build>    <finalName>minifast-web</finalName>    <resources>            <resource>                <directory>src/main/resources</directory>                <filtering>true</filtering>                <excludes>                    <exclude>dev/*</exclude>                    <exclude>test/*</exclude>                    <exclude>prd/*</exclude>                </excludes>            </resource>        </resources>        <plugins>            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-war-plugin</artifactId>                <version>2.1.1</version>                <configuration>                    <archive>                        <addMavenDescriptor>false</addMavenDescriptor>                    </archive>                    <webResources>                        <resource>                            <directory>src/main/resources/${package.environment}</directory>                            <targetPath>WEB-INF/classes</targetPath>                            <filtering>true</filtering>                        </resource>                    </webResources>                </configuration>            </plugin>        </plugins>  </build>  <profiles>        <profile>            <id>dev</id>            <properties>                <package.environment>dev</package.environment>            </properties>            <activation>                <activeByDefault>true</activeByDefault>            </activation>        </profile>         <profile>            <id>test</id>            <properties>                <package.environment>test</package.environment>            </properties>        </profile>        <profile>            <id>prd</id>            <properties>                <package.environment>prd</package.environment>            </properties>        </profile>    </profiles>

profiles配置使maven可以切换不同目录


web目录结构



install会执行默认的dev环境

可以使用-P命令传入对应参数prd 或者test

clean install -P prd

0 0