1
這是我的老POM的<build>
標記,它是工作:Maven的POM多環境profiels
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.2</version>
</plugin>
</plugins>
<finalName>test</finalName>
</build>
現在我想對每個階段3個不同的api.properties文件:PROD,開發,測試。所以我繼續並遵循maven的<profile>
教程。這就是我結束了只是督促和測試階段(完全拆除舊<build>
標籤):
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<tasks>
<delete file="${project.build.outputDirectory}/api.prod.properties" />
<delete file="${project.build.outputDirectory}/api.dev.properties" />
<copy file="src/main/resources/api.test.properties"
tofile="${project.build.outputDirectory}/api.properties" />
</tasks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.2</version>
</plugin>
</plugins>
<finalName>test</finalName>
</build>
</profile>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<tasks>
<delete file="${project.build.outputDirectory}/api.test.properties" />
<delete file="${project.build.outputDirectory}/api.dev.properties" />
<copy file="src/main/resources/api.prod.properties"
tofile="${project.build.outputDirectory}/api.properties" />
</tasks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.2</version>
</plugin>
</plugins>
<finalName>test</finalName>
</build>
</profile>
</profiles>
並沒有真正但是工作。將生成一個.war而不是我想要的3個戰爭(test-prod.war,test-dev.war,...),並且生成的戰爭將包含所有3個.properties文件,而不是它應該擁有的那個。爲什麼和我能做些什麼來解決它?我對maven很新穎......謝謝!
你怎麼跑了Maven構建?選擇了全部三個配置文件?爲每個配置文件運行一次應該爲您提供三種不同的工件。 – Abaddon666
@ Abaddon666:我只是像往常一樣在日食中運行maven install ...我如何運行它「不同」? – Shiuyin
我通常從命令行運行maven build,然後看起來像例如'mvn clean install -Ptest'用於運行測試配置文件。否則,你必須谷歌如何選擇配置文件可用於您正在使用的maven插件 – Abaddon666