代码之家  ›  专栏  ›  技术社区  ›  Robert Munteanu

发布时修改GWT的user.agent

  •  9
  • Robert Munteanu  · 技术社区  · 16 年前

    在开发时,我设置了 user.agent 属性设置为单个值,以缩短编译时间。发布时,我为所有用户代理构建了一个WAR文件。

    不幸的是,我似乎总是忘记切换属性,或者:

    • 正在准备一个不完全支持浏览器的WAR文件(谢天谢地,尚未部署)。

    2 回复  |  直到 16 年前
        1
  •  7
  •   Robert Munteanu    14 年前

    您需要有两个不同的.gwt.xml文件—一个用于开发,另一个用于生产。

    中的“重命名模块”部分有一个很好的示例 Developer Guide/Organizing projects .

    用于开发的gwt.xml文件将继承用于生产的gwt.xml文件,并设置user.agent属性。例如。:

    <module rename-to="com.foo.MyModule">
      <inherits name="com.foo.MyModule" />
      <set-property name="user.agent" value="ie6" />
    </module>
    

    现在,在进行开发时,您将使用development gwt.xml文件,以及在进行生产构建时。您将使用生产gwt.xml文件。


    Maven Recipe : GWT development profile

        2
  •  2
  •   Gabriel    14 年前

    创建一个MavenFilteredUserAgent模块,用于设置 user.agent 来自pom.xml中的各种概要文件。

    ...
    <set-property name="user.agent" value="${gwt.compile.user.agent}" />
    ...
    

    pom.xml

    ...
    <properties>
      <!-- By default we still want all five rendering engines when none of the following profiles is explicitly specified -->
      <gwt.compile.user.agent>ie6,ie8,gecko,gecko1_8,safari,opera</gwt.compile.user.agent>
    </properties>
    <profiles>
      <profile>
        <id>gwt-firefox</id>
        <properties>
          <gwt.compile.user.agent>gecko1_8</gwt.compile.user.agent>
        </properties>
      </profile>
    </profiles>
    <!-- Add additional profiles for the browsers you want to singly support -->
    ....
    <build>
      <resources>
        <resource>
          <!-- Put the filtered source files into a directory that later gets added to the build path -->
          <directory>src/main/java-filtered</directory>
          <filtering>true</filtering>
          <targetPath>${project.build.directory}/filtered-sources/java</targetPath>
        </resource>
        <resource>
          <directory>${project.basedir}/src/main/resources</directory>
        </resource>
        </resources>
      <plugins>
      ...
      <plugin>
        <!-- Add the filtered sources directory to the build path-->
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/filtered-sources/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
    

    然后你可以像这样为firefox构建。

    mvn install -Pgwt-firefox

    http://9mmedia.com/blog/?p=854 有更多的细节。