2012-09-10 65 views
0

我使用gwt與maven插件。我web.xml看起來是這樣的:gwt別名資源與maven插件

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"> 

<!-- Servlets --> 
<servlet> 
    <servlet-name>queryServiceImpl</servlet-name> 
    <servlet-class>com.vo.search.server.QueryServiceImpl</servlet-class> 
</servlet> 

<servlet-mapping> 
    <servlet-name>queryServiceImpl</servlet-name> 
    <url-pattern>/admin/queryService</url-pattern> 
</servlet-mapping> 

<!-- Default page to serve --> 
<welcome-file-list> 
    <welcome-file>Admin.html</welcome-file> 
</welcome-file-list> 
</web-app> 

而我的模塊Admin.gwt.xml看起來是這樣的:

<module rename-to='admin'> 
<!-- Inherit the core Web Toolkit stuff. --> 
<inherits name="com.google.gwt.core.Core" /> 
<inherits name='com.google.gwt.user.User' /> 
<inherits name="com.google.gwt.i18n.I18N" /> 
<inherits name="com.google.gwt.i18n.CldrLocales" /> 
<inherits name="com.google.gwt.user.theme.clean.CleanResources" /> 

<!-- Enable debug ID. --> 
<inherits name="com.google.gwt.user.Debug" /> 
<set-property name="gwt.enableDebugId" value="true" /> 

<!-- We need the JUnit module in the main module, --> 
<!-- otherwise eclipse complains (Google plugin bug?) --> 
<!-- <inherits name='com.google.gwt.junit.JUnit' /> --> 

<!-- Inherit the default GWT style sheet. You can change --> 
<!-- the theme of your GWT application by uncommenting --> 
<!-- any one of the following lines. --> 
<inherits name='com.google.gwt.user.theme.clean.Clean' /> 
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> --> 
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> 
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> --> 

<!-- Other module inherits --> 

<!-- Specify the app entry point class. --> 
<entry-point class='com.vo.search.client.Admin' /> 

<!-- Specify the app entry point class. --> 

<!-- Specify the paths for translatable code --> 
<source path='client' /> 
<source path='shared' /> 


</module> 

最後,我pom.xml看起來是這樣的:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 

<!-- POM file generated with GWT webAppCreator --> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.vo.search</groupId> 
<artifactId>search-admin</artifactId> 
<packaging>war</packaging> 
<version>1.0</version> 
<name>Admin</name> 

<properties> 
    <!-- Convenience property to set the GWT version --> 
    <gwtVersion>2.5.0-rc1</gwtVersion> 
    <!-- GWT needs at least java 1.5 --> 
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-servlet</artifactId> 
     <version>${gwtVersion}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-user</artifactId> 
     <version>${gwtVersion}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.7</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.0.0.GA</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.0.0.GA</version> 
     <classifier>sources</classifier> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
    <!-- Generate compiled stuff in the folder used for developing mode --> 
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory> 

    <plugins> 

     <!-- GWT Maven Plugin --> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>gwt-maven-plugin</artifactId> 
      <version>2.5.0-rc1</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>compile</goal> 
         <goal>test</goal> 
         <goal>i18n</goal> 
         <goal>generateAsync</goal> 
        </goals> 
       </execution> 
      </executions> 
      <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
       documentation at codehaus.org --> 
      <configuration> 
       <runTarget>Admin.html</runTarget> 
       <hostedWebapp>${webappDirectory}</hostedWebapp> 
       <i18nMessagesBundle>com.vo.search.client.Messages</i18nMessagesBundle> 
      </configuration> 
     </plugin> 

     <!-- Copy static web files before executing gwt:run --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1.1</version> 
      <executions> 
       <execution> 
        <phase>compile</phase> 
        <goals> 
         <goal>exploded</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <webappDirectory>${webappDirectory} </webappDirectory> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.5</source> 
       <target>1.5</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
</project> 

構建和運行項目工作正常。當試圖訪問我在控制檯中看到的頁面:

[WARN] Aliased resource: file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/admin/admin.nocache.js==file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/Admin/Admin.nocache.js 
[WARN] Aliased resource: file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/admin/admin.nocache.js==file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/Admin/Admin.nocache.js 
[WARN] 404 - GET /admin/admin.nocache.js (127.0.0.1) 1408 bytes 
    Request headers 
     Host: 127.0.0.1:8888 
     Connection: keep-alive 
     User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like  Gecko) Chrome/22.0.1229.39 Safari/537.4 
     Accept: */* 
     Referer: http://127.0.0.1:8888/Admin.html?gwt.codesvr=127.0.0.1:9997 
     Accept-Encoding: gzip,deflate,sdch 
     Accept-Language: en-US,en;q=0.8 
     Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 
    Response headers 
     Content-Type: text/html; charset=iso-8859-1 
     Content-Length: 1408 

我認爲問題是,它看起來文件admin.nocache.jsadmin DIR但是生成的目錄實際上是Admin即使我rename-to屬性是admin模塊中配置文件。更改rename-to屬性以匹配沒有幫助。

這是一個被gwt-maven-plugin archetype創建了項目組織: enter image description here

+1

嗯,我認爲問題是,你必須在'管理員/ Admin.nocache.js' 'src/main/webapp'開頭。 –

+0

@ThomasBroyer你能否詳細說明一下? – Michael

+0

生成的代碼只能在'target',而不是'src'中。我不知道爲什麼你在'src/main/webapp'中有'Admin/Admin.nocache.js',但是首先要解決這個問題。 –

回答

1

請檢查您的Admin.html。我認爲admin.nocache.js應該是:

<script type="text/javascript" language="javascript" src="../admin/admin.nocache.js"></script> 

您的文件 ... search-admin/src/main/webapp/Admin/Admin.nocache.js

應該在這裏: ... search-admin/src/main/Admin/Admin.nocache.js

+0

我沒有發現要檢查'Admin.html'。確實是'src =「admin/admin.nocache.js」'isntead'src =「Admin/Admin.nocache.js」',但我會將它留在'webapp'目錄下。我仍然不明白maven決定如何在'webapp'目錄下命名模塊目錄的方式。我認爲它是在Admin.gwt.xml文件中用'rename-to'屬性確定的,但是當我將它設置爲'admin'時,它仍然創建目錄爲'webapp \ Admin'而不是'webapp \ admin ' – Michael

+0

我還沒有詳細研究過你的POM,但顯然你不應該有任何東西被生成到'src'中(即那應該是你的目標)。你使用'mvn gwt:run'來啓動DevMode嗎? –

+0

@ThomasBroyer代碼也正在生成到目標中。我沒有看到'pom.xml'中的任何地方,它告訴它將它編譯成'src'。無論我將模塊更改爲「admin」,所創建的目錄仍然是「Admin」 – Michael

1

如果你使用谷歌Eclipse插件(而不是mvn gwt:run)推出DevMode的,然後按照這些規則:https://developers.google.com/eclipse/docs/faq#gwt_with_maven

特別是,最重要的是,不要選擇src/main/webapp作爲WAR目錄,這就是爲什麼DevMode的在那裏產生的文件,它只能導致你的問題:GWT module may need to be (re)compiled REDUX

+0

我以爲搬到Maven會很直接,現在我發現它不是。所以我必須再進一步調查。我有一個正常工作的gwt項目,我認爲最好的方法是創建一個gwt maven原型並將所有源文件複製到它。您認爲,組織該項目的最佳方式是什麼? – Michael

+1

看看[我的原型](github.com/tbroyer/gwt-maven-archetypes)。仍然需要一些工作,但總體思路是:獨立模塊中的客戶端和服務器代碼分離,不要將src/main/resources用於GWT客戶端資源(UiBinder模板,CssResource樣式表,消息屬性文件等等)。 ),因爲它們是要編譯的源的一部分。我的最終目標是創建一些自定義的Maven包裝類型和生命週期,但我們還沒有。 –