【问题标题】:How to set property into gwt.xml file via maven properties?如何通过 Maven 属性将属性设置为 gwt.xml 文件?
【发布时间】:2013-01-07 05:07:51
【问题描述】:

我在根 pom.xml 文件中有一个属性:gecko1_8。我想把它放到 gwt.xml 文件中。

所以我把这个属性放到gwt.xml中:

我在构建部分添加了以下内容:

<resources>
  <resource>
  <directory>src/main/resources</directory>
  <filtering>true</filtering>
    <excludes>
      <exclude>VAADIN.themes/*</exclude>
    </excludes>
  </resource>
</resources>

但最终构建失败并出现错误:

错误:无效的属性值“${gwt.user.agents}”

错误:解析 XML 失败

如何通过属性将 pom.xml 中的值放置到 gwt.xml 文件中?

更新

有趣的事情。当我使用“mvn resources:resources”时,属性的值会正确写入 gwt.xml 文件,但如果我运行“mvn clean install -pl com.myproject.module:submodule”,它会因“无效的属性值”而失败。

【问题讨论】:

    标签: gwt maven


    【解决方案1】:

    您必须像这样在 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>
    

    然后将其设置在您的YourGWTModule.gwt.xml 中,如下所示:

    <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>
    

    最后使用配置文件运行 maven:

    mvn -P gecko install
    

    【讨论】:

    • 但是如果我有几个使用 GWT 的模块怎么办?我必须在每个模块 pom.xml 中编写(复制粘贴)此类配置文件吗?我的意思是,如果我只想使用 -pl 选项构建一个特定的模块。我认为在根 pom.xml 中放置属性就足够了……当然还有一些附加配置。
    • @Dragon 我认为你的解决方案很好,或者你可以定义一个父 pom。
    • 注意(供后代使用;)):如果你有一个 Spring Boot 应用程序,你应该使用@....@ 而不是 ${...},如下所述:stackoverflow.com/questions/36501017/…跨度>
    【解决方案2】:

    有一件事我没有提到,但它似乎太重要了。在构建期间使用的插件可以有自己的目标。其中一个目标可以“重做” maven-resource-plugin 所做的事情。

    所以我有一个插件 vaadin-maven-plugin:

    <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>
    

    删除&lt;goal&gt;resources&lt;/goal&gt; 解决了这个问题。现在mvn clean install 可以正确过滤我的 gwt.xml 中的属性。

    希望这个解决方案能帮助那些将在这样的问题上运行的人。

    【讨论】:

      猜你喜欢
      • 2016-04-15
      • 2018-09-02
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-15
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多