如何通过maven属性将属性设置为gwt.xml文件?
我在根pom.xml文件中有一个属性:gecko1_8。我想把它放到gwt.xml文件中 所以我把这个属性放到gwt.xml中: 我在构建部分添加了以下内容:如何通过maven属性将属性设置为gwt.xml文件?,gwt,maven,Gwt,Maven,我在根pom.xml文件中有一个属性:gecko1_8。我想把它放到gwt.xml文件中 所以我把这个属性放到gwt.xml中: 我在构建部分添加了以下内容: <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <excl
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>VAADIN.themes/*</exclude>
</excludes>
</resource>
</resources>
src/main/resources
真的
瓦丁主题酒店/*
但最终生成失败,出现错误:
错误:无效的属性值“${gwt.user.agents}”
错误:解析XML时失败
如何通过属性将pom.xml中的值放置到gwt.xml文件中
更新
有趣的事。当我使用“mvn resources:resources”时,属性值会正确写入gwt.xml文件,但如果我运行“mvn clean install-pl com.myproject.module:submodule”,则会出现“无效属性值”的故障。您必须在pom中定义一个maven配置文件(最好为每种情况定义一个特定的配置文件),如下所示:
<profile>
<id>gecko</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<user.agent.gecko>
<![CDATA[<set-property name="user.agent" value="gecko,gecko1_8" />]]>
</user.agent.gecko>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*YourGWTModule.gwt.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<defaultGoal>process-resources</defaultGoal>
</build>
</profile>
<properties>
<!--<user.agent>ie6,ie8,gecko,gecko1_8,opera,safari</user.agent>-->
<user.agent.all> </user.agent.all>
<user.agent.ie6> </user.agent.ie6>
<user.agent.ie8> </user.agent.ie8>
<user.agent.gecko> </user.agent.gecko>
<user.agent.opera> </user.agent.opera>
<user.agent.safari> </user.agent.safari>
</properties>
<set-property name="locale" value="default" />
<!-- Specified through pom.xml profiles -->
${user.agent.all}
${user.agent.ie6}
${user.agent.ie8}
${user.agent.gecko}
${user.agent.safari}
${user.agent.opera}
</module>
最后使用profile运行maven:
mvn -P gecko install
有一件事我没有提到,但似乎太重要了。构建期间使用的插件可以有自己的目标。其中一个目标可以“重做”maven资源插件所做的事情 所以我有一个插件vaadin maven插件:
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<configuration>
...
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
com.vaadin
vaadin maven插件
${vaadin.plugin.version}
...
资源
编译
删除资源
解决了这个问题。现在,mvn clean install
正确地过滤my gwt.xml中的属性
希望此解决方案能够帮助解决此类问题的用户。但如果我有几个使用GWT的模块,该怎么办?我必须在每个模块pom.xml中编写(复制粘贴)这样的配置文件?我的意思是,如果我只想使用-pl选项构建一个特定的模块。我认为将属性放在根pom.xml中就足够了…当然还有一些额外的配置。@Dragon我认为您的解决方案很好,或者您可以定义一个父pom.Note(对于后代;):如果您有Spring Boot应用程序,您应该使用@…@而不是${…},如下所述: