2009-06-07 18 views
9

Khi phát triển, tôi đặt thuộc tính user.agent thành một giá trị duy nhất, để giữ thời gian biên dịch xuống. Khi phát hành, tôi có một tệp WAR được xây dựng cho tất cả các tác nhân người dùng.Sửa đổi user.agent của GWT khi phát hành

tôi dường như không may để tiếp tục lãng quên để chuyển đổi tài sản, hoặc là:

  • lãng phí thời gian phát triển chờ biên dịch, hoặc
  • chuẩn bị một tập tin WAR với sự hỗ trợ trình duyệt không đầy đủ (chưa triển khai, may mắn).

Tôi muốn tự động hóa điều này, tốt nhất là sử dụng plugin maven-release.

+0

Trang web của bạn có thể truy cập công khai không? Ở đâu? –

+0

Tôi cũng muốn xem nó cho Ant. – Glenn

+0

@Don Branson: không, trang web không được công khai. –

Trả lời

7

Bạn muốn có 2 tệp .gwt.xml khác nhau - một tệp được sử dụng để phát triển và một tệp được sử dụng để sản xuất.

Có một ví dụ hay về phần 'Đổi tên mô-đun' của Developer Guide/Organizing projects.

Tệp gwt.xml được sử dụng để phát triển sẽ được kế thừa từ tệp gwt.xml được sử dụng để sản xuất và đặt thuộc tính user.agent. ví dụ:

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

Bây giờ, khi phát triển, bạn sẽ sử dụng tệp gwt.xml phát triển và khi xây dựng sản xuất. bạn sẽ sử dụng tệp gwt.xml sản xuất.


Cách dễ nhất để đạt được điều này với Maven là kích hoạt mô-đun phát triển bằng hồ sơ. Tôi đã viết chi tiết về điều này tại Maven Recipe : GWT development profile.

+0

Cảm ơn câu trả lời. Tôi đã thử nó (sử dụng GWT 1.5) và biên dịch hoạt động như mong đợi. Chướng ngại duy nhất là Application.html của tôi vẫn đề cập đến Application.nocache.js, thay vì ApplicationFirefox.nocache.js. Tham chiếu: http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_CompileOnePermutation –

+0

Gwt.xml có được sử dụng cho bắt đầu xây dựng firefox với ? – Chi

+0

bạn là chính xác, điều này 'đổi tên-to' là mất tích.Tôi sẽ cập nhật câu trả lời với cài đặt maven mà tôi đã sử dụng. –

2

Tạo mô-đun MavenFilteredHơn mô-đun chung đặt user.agent từ các cấu hình khác nhau trong tệp pom.xml.

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

Có tất cả các module của bạn kế thừa các mô-đun MavenFilteredUserAgent.

Sau đó, bạn có thể xây dựng cho chỉ firefox như vậy.

mvn install -Pgwt-firefox

http://9mmedia.com/blog/?p=854 có thêm chi tiết.

+1

Đối với [GWT 2.1.1] (http://groups.google.com/group/google-web-toolkit/browse_thread/thread/6f2418947d7efeb9/2a6615d8b719089), bạn sẽ muốn xóa tắc kè khỏi danh sách mặc định. Về cơ bản, điều này về cơ bản sẽ có cùng một danh sách như là [mô-đun UserAgent cơ bản] (http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user /UserAgent.gwt.xml) – Gabriel

+1

Tôi luôn nhận được: [INFO] [LRI] Giá trị thuộc tính không hợp lệ '$ {gwt.compile.user.agent}' [INFO] [ERROR] Không thành công khi phân tích cú pháp XML – Alex

Các vấn đề liên quan