1

同じプロジェクトでRestletをGWTとうまく連携させるのに問題があります。私はRestletsのウェブサイトからの例を無駄に試してきました

Eclipse、Maven2プラグイン、GWT、およびRestletGWTを使用しています。私はこれまでこのGWTプロジェクトでサーバー側のコードを使用したことがなく、カスタムセットアップが含まれていることを知っています。とりあえず、GWTホストモードで組み込みのJettyを使用してローカルにデプロイしています。フロントエンドを表示できますが、バックエンドが実行されていません。

これを例のweb.xmlファイルに追加しました(当面は例をプロジェクトにドロップしようとしています)。

    <servlet>
    <servlet-name>adapter</servlet-name>
    <servlet-class>org.restlet.ext.gwt.GwtShellServletWrapper</servlet-class>
    <init-param>
        <param-name>org.restlet.application</param-name>
        <param-value>org.restlet.example.gwt.server.TestServerApplication</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>adapter</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

web.xmlファイルがwarデプロイメントディレクトリとは別に配置されていることに気づきました。私のプロジェクトディレクトリ構造は次のように設定されています。

Project Root
   src/main/java
   src/main/resources
   src/main/test
   JRE
   Maven Dependecies
   GWT SDK
   src
      main
          webapp
              WEB-INF
                 web.xml
   target
   war
      <my project dir>
      WEB-INF
         lib
   pom.xml

したがって、warファイルのWEB-INFディレクトリの下にweb.xmlはありません。私はこのタイプのアプリケーションに慣れていないので、ディレクトリ構造と、GWTプロジェクトがこれらのディレクトリにどのようにコンパイルされているかを理解していないことが問題である可能性があります。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 generated by gwt-maven-plugin archetype
  -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.tdc</groupId>
  <artifactId>Propspace</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <properties>

      <!-- convenience to define GWT version in one place -->
      <gwt.version>2.0.0</gwt.version>

      <!--  tell the compiler we can use 1.5 -->
      <maven.compiler.source>1.5</maven.compiler.source>
      <maven.compiler.target>1.5</maven.compiler.target>

  </properties>

  <repositories>
    <repository>
        <snapshots>
        </snapshots>
        <id>com.smartgwt</id>
        <name>smartgwt</name>
        <url>http://www.smartclient.com/maven2</url>
    </repository>
    <repository>
        <id>maven-restlet</id>
        <name>Public online Restlet repository</name>
        <url>http://maven.restlet.org</url>
    </repository>
  </repositories>
  <dependencies>

      <!--  GWT dependencies (from central repo) -->
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwt.version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwt.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.smartgwt</groupId>
        <artifactId>smartgwt</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>3.1.14</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.restlet</groupId>
        <artifactId>org.restlet.ext.gwt</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.restlet</groupId>
        <artifactId>org.restlet.ext.json</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.restlet</groupId>
        <artifactId>org.restlet.ext.xml</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.gwt</groupId>
        <artifactId>org.restlet</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet.ext.servlet</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet.ext.gwt</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <outputDirectory>war/WEB-INF/classes</outputDirectory>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>generateAsync</goal>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <runTarget>com.tdc.Propspace.Application/Application.html</runTarget>
        </configuration>
      </plugin>
      <!--
          If you want to use the target/web.xml file mergewebxml produces,
          tell the war plugin to use it.
          Also, exclude what you want from the final artifact here.
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>target/web.xml</webXml>
                    <warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
                </configuration>
            </plugin>
            -->

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.0.2</version>
          <configuration>
            <source>${maven.compiler.source}</source>
            <target>${maven.compiler.target}</target>
          </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1-beta-1</version>
        <configuration>
          <warSourceDirectory>war</warSourceDirectory>
          <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.2</version>
      </plugin>
    </plugins>
  </build>

</project>

どんな助けでも大歓迎です!さらに情報を提供する必要がある場合はお知らせください。

ありがとう

4

2 に答える 2

1

pom.xml を見ずに問題が何であるかを正確に判断するのは困難ですが、GWT 開発のための Maven のセットアップ の下部に記載されているように maven-war-plugin を構成しましたか?

maven-war-plugin の設定

Google Eclipse プラグインでは、Web アプリケーションを展開された WAR として /war (ハードコードされたパス) に作成する必要があります。この要件を満たすには、次の 2 つのオプションがあります。

  • src/main/webappフォルダーをに移動し、 /warmaven-war-pluginwarSourceDirectory パラメーターを構成します。展開された WAR レイアウトを構築するために webapp ソースが使用されるため、これはインプレース セットアップです。
  • /war 標準の代わりに(webappDirectoryパラメーター)で webapp をビルドするように maven-war-plugin を構成しますoutputDirectory

gwt-maven-plugin には、選択したオプションを構成するためのブール型の inplace パラメーターがあります。このinplaceモードは、JSP ファイルで行われた変更を確認するためにビルド/パッケージ化/デプロイが不要なため、JSP を使用する場合に興味深いものです。CSS などの静的ファイルにも同じことが当てはまります。

以下は、インプレース セットアップ用の maven-war-plugin の一般的な構成です。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.0.2</version>
  <configuration>
    <warSourceDirectory>war</warSourceDirectory>
    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
  </configuration>
</plugin> 

これが役立つかどうか教えてください (その場合、何が問題を引き起こしているのか不明な点を明確にすることを躊躇しないでください)。

PS: また、この前の回答もご覧ください。

于 2010-05-02T21:13:18.000 に答える
0

問題は、war プラグインがそこから web.xml ファイルを取得するように構成されていても、web.xml ファイルが src/main/webapp/WEB-INF/web.xml にあり、war/ に配置されなかったことです。 WEB-INF/ フォルダー。それを修正するために、手動で web.xml ファイルを war/WEB-INF ディレクトリにコピーしたところ、うまくいきました。

于 2010-05-03T23:24:27.797 に答える