[英]Maven Profiles - How do i get the values assigned to properties in the .properties file and assign them to variables in my class?
[英]How do I tell Maven to package the file compared to my profiles
我的maven
項目中有這種結構
src
|
|_java
|_resources
|_webapp
|
|_addin
|
|_fckconfig.dev.js
|_fckconfig.js
|_fckconfig.prod.js
我的pom.xml:
<properties>
<webXmlfolder>default</webXmlfolder>
<profileVersion>defaultVersion</profileVersion>
<majorVersion>2</majorVersion>
<minorVersion>50.3-0</minorVersion>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<profileVersion>DEV</profileVersion>
<webXmlfolder>dev</webXmlfolder>
</properties>
</profile>
<profile>
<id>preprod</id>
<properties>
<profileVersion>PREPROD</profileVersion>
<webXmlfolder>preprod</webXmlfolder>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileVersion>PROD</profileVersion>
<webXmlfolder>prod</webXmlfolder>
</properties>
</profile>
</profiles>
<!-- FIN Profiles -->
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<include>**/*.${webXmlfolder}.*</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp/addin</directory>
<filtering>true</filtering>
<includes>
<include>/addin/*.${webXmlfolder}.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-web.xml</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF</outputDirectory>
<resources>
<resource>
<directory>src/main/config/${webXmlfolder}/WEB-INF</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
當我執行mvn clean install -P prod
我只想擁有:
src
|
|_java
|_resources
|_webapp
|
|_addin
|
|_fckconfig.prod.js
但是現在什么也沒發生,我總是歸檔,為什么?
正如為maven war plugin所抱怨的那樣,src / main / webapp是Web應用程序源的默認文件夾。 因此,src / main / webapp中的所有文件都會自動添加到war中。 嘗試將addin文件夾移到src / main / webapp之外。 如果您無法移動文件夾,則需要使用“ exclude”標簽,如此處所述 。
我建議您先使用maven-war-plugin
來根據您的配置文件配置WAR文件的內容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<webXml>src/main/config/${webXmlfolder}/WEB-INF/web.xml</webXml>
<warSourceIncludes>*.*</warSourceIncludes>
<warSourceIncludes>addin/*.${webXmlfolder}.js</warSourceIncludes>
</configuration>
</execution>
</executions>
</plugin>
順便說一下,我注意到如果在package
階段執行它,則copy-web.xml插件可能存在不兼容性,因為war插件也總是在同一階段執行:
<webxml>
maven-war-plugin
中獲取<webxml>
節點,但是假設您的web.xml
文件不需要進行過濾。 (是嗎?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.