1

我无法让 Restlet 在同一个项目中与 GWT 配合得很好。我一直在尝试来自 Restlets网站的示例,但无济于事

我正在使用 Eclipse、Maven2 插件、GWT 和 Restlet GWT。我以前从未在这个 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 文件与我的战争部署目录分开放置。我的项目目录结构设置如下。

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,很难说出问题到底是什么,但是您是否按照Setup Maven for GWT development底部的描述配置了 maven-war-plugin :

配置 maven-war-plugin

Google Eclipse 插件要求将您的 Web 应用程序创建为 /war(硬编码路径)中的爆炸 WAR。要满足此要求,您有两种选择:

  • 将您的src/main/webapp文件夹移动到/war并配置 maven-war-pluginwarSourceDirectory 参数。这是就地设置,因为 webapp 源将用于构建展开的 WAR 布局。
  • /war 配置 maven-war-plugin 以在(参数)中构建 webappwebappDirectory而不是标准的outputDirectory.

gwt-maven-plugin 有一个布尔 inplace 参数来配置您选择的选项。如果您使用 JSP,则该inplace模式会很有趣,因为无需构建/打包/部署即可查看 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

好吧,问题是我的 web.xml 文件位于我的 src/main/webapp/WEB-INF/web.xml 中,即使我的战争插件被配置为从那里获取我的 web.xml 文件,它没有将它放在我的战争/ WEB-INF/ 文件夹。为了解决这个问题,我手动将 web.xml 文件复制到了 war/WEB-INF 目录中并且它工作了。

于 2010-05-03T23:24:27.797 回答