2009-06-07 25 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有更多的細節。