2009-06-07 27 views
9

开发时,我将user.agent属性设置为单个值,以减少编译时间。发布时,我有一个为所有用户代理构建的WAR文件。在发布时修改GWT的user.agent

我不幸似乎总是忘记切换属性,则:

  • 浪费开发时间等待编译或
  • 准备不完整的浏览器支持一个WAR文件(尚未部署,谢天谢地)。

我想自动执行此操作,最好使用maven-release-plugin。

+0

您的网站是否可公开访问?哪里? – 2009-06-07 23:29:55

+0

我也想为Ant看到它。 – Glenn 2009-06-07 23:30:39

+0

@唐布兰森:不,该网站不公开。 – 2009-06-08 08:31:41

回答

7

您想拥有2个不同的.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> 

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


使用Maven实现此目的的最简单方法是使用配置文件激活开发模块。我在Maven Recipe : GWT development profile上详细写了这个。

2

创建一个MavenFilteredUserAgent模块,该模块从pom.xml中的各种配置文件设置user.agent

MavenFilteredUserAgent.gwt.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> 
... 

有所有模块的继承MavenFilteredUserAgent模块。

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

mvn install -Pgwt-firefox

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