使用 GWT RPC 的 GAE 上的 ClassNotFoundException

发布于 2024-12-09 15:38:10 字数 5286 浏览 0 评论 0原文

我正在使用 PlayN 开发游戏。它包含一个类型,GameEvent,在 my-game-core 项目中定义。我的 GWT 和 GAE 代码位于 my-game-html 中,其中有 my-game-core 作为 Maven 依赖项。

这是服务实现:

package com.mygame.html.server;

import com.mygame.core.event.GameEvent;
import com.mygame.html.client.ServerEventHandlerService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class ServerEventHandlerServiceImpl extends RemoteServiceServlet
        implements ServerEventHandlerService {

    @Override
    public String handleEvent(final GameEvent event) {
        return "holy porkchops batman!";
    }

}

编译得很好。但是,当我尝试在本地开发服务器上运行时调用该服务时,出现以下错误:

SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
java.lang.NoClassDefFoundError: com/mygame/core/event/GameEvent
...
Caused by: java.lang.ClassNotFoundException: com.mygame.core.event.GameEvent
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 39 more

如果我取出 GameEvent 并将其替换为 String 等类型,一切正常。

我在这里可能做错了什么? GameEvent 有一个默认构造函数。

更新:这是 *-html 项目的 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>mygame-game</artifactId>
    <groupId>com.mygame</groupId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>
  <artifactId>mygame-game-html</artifactId>
  <packaging>war</packaging>
  <name>my game html build</name>

  <properties>
    <gwt.module>com.mygame.MygameGame</gwt.module>
    <gwt.name>mygame</gwt.name>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.mygame</groupId>
      <artifactId>mygame-game-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.playn</groupId>
        <artifactId>playn-html</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <outputDirectory>war/WEB-INF/classes</outputDirectory>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <warSourceDirectory>war</warSourceDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <!-- we need class metadata, override PlayN's disabling of such -->
        <configuration>
          <disableClassMetadata>false</disableClassMetadata>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.8</version>
        <configuration>
          <downloadSources>true</downloadSources>
          <downloadJavadocs>false</downloadJavadocs>
          <wtpversion>2.0</wtpversion>
          <additionalBuildcommands>
            <buildCommand>
              <name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
            </buildCommand>
          </additionalBuildcommands>
          <additionalProjectnatures>
            <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
          </additionalProjectnatures>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

更新 2:在 war/WEB-INF/lib 中,我有:

  • appengine-api-1.0-sdk-1.5.4.jar
  • appengine-api-1.0-sdk-1.5.5.jar
  • appengine-api-labs-1.5.4.jar
  • appengine-api-labs-1.5.5.jar
  • appengine-jsr107cache-1.5.4.jar
  • appengine-jsr107cache-1.5.5.jar
  • datanucleus-appengine-1.0.9.final.jar
  • datanucleus-core-1.1.5.jar
  • datanucleus -jpa-1.1.5.jar
  • geronimo-jpa_3.0_spec-1.1.1.jar
  • geronimo-jta_1.1_spec-1.1.1.jar
  • gwt-servlet.jar
  • jdo2-api-2.3-eb.jar
  • jsr107cache-1.1.jar

I'm using PlayN to develop a game. It contains a type,GameEvent, defined in my-game-core project. My GWT and GAE code lives in my-game-html, which has my-game-core as a Maven dependency.

Here is the service impl:

package com.mygame.html.server;

import com.mygame.core.event.GameEvent;
import com.mygame.html.client.ServerEventHandlerService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class ServerEventHandlerServiceImpl extends RemoteServiceServlet
        implements ServerEventHandlerService {

    @Override
    public String handleEvent(final GameEvent event) {
        return "holy porkchops batman!";
    }

}

This compiles just fine. However, when I try to call the service at runtime on the local dev server, I get the following error:

SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
java.lang.NoClassDefFoundError: com/mygame/core/event/GameEvent
...
Caused by: java.lang.ClassNotFoundException: com.mygame.core.event.GameEvent
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 39 more

If I take out GameEvent and replace it with a type like String, everything works fine.

What could I be doing wrong here? GameEvent has a default constructor.

Update: Here is pom.xml for the *-html project:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>mygame-game</artifactId>
    <groupId>com.mygame</groupId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>
  <artifactId>mygame-game-html</artifactId>
  <packaging>war</packaging>
  <name>my game html build</name>

  <properties>
    <gwt.module>com.mygame.MygameGame</gwt.module>
    <gwt.name>mygame</gwt.name>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.mygame</groupId>
      <artifactId>mygame-game-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.playn</groupId>
        <artifactId>playn-html</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <outputDirectory>war/WEB-INF/classes</outputDirectory>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <warSourceDirectory>war</warSourceDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <!-- we need class metadata, override PlayN's disabling of such -->
        <configuration>
          <disableClassMetadata>false</disableClassMetadata>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.8</version>
        <configuration>
          <downloadSources>true</downloadSources>
          <downloadJavadocs>false</downloadJavadocs>
          <wtpversion>2.0</wtpversion>
          <additionalBuildcommands>
            <buildCommand>
              <name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
            </buildCommand>
          </additionalBuildcommands>
          <additionalProjectnatures>
            <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
          </additionalProjectnatures>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Update 2: In war/WEB-INF/lib, I have:

  • appengine-api-1.0-sdk-1.5.4.jar
  • appengine-api-1.0-sdk-1.5.5.jar
  • appengine-api-labs-1.5.4.jar
  • appengine-api-labs-1.5.5.jar
  • appengine-jsr107cache-1.5.4.jar
  • appengine-jsr107cache-1.5.5.jar
  • datanucleus-appengine-1.0.9.final.jar
  • datanucleus-core-1.1.5.jar
  • datanucleus-jpa-1.1.5.jar
  • geronimo-jpa_3.0_spec-1.1.1.jar
  • geronimo-jta_1.1_spec-1.1.1.jar
  • gwt-servlet.jar
  • jdo2-api-2.3-eb.jar
  • jsr107cache-1.1.jar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的好友蓝忘机已上羡 2024-12-16 15:38:10

您在 gwt 启动的 jetty 的运行时类路径中缺少依赖项 my-game-core 。

您是否使用 mvn eclipse:eclipse 将您的项目导入到 eclipse 中?
也许您的运行时类路径仍然指向您的本地 Maven 存储库,但您已经更改了 Eclipse 项目 (my-game-core)。查看您的 Eclipse 类路径,并确保其上只有其他项目,而不是存储库中的 jar。

另请检查运行配置中的类路径选项卡。

you are missing your dependency my-game-core in the runtime classpath of the jetty that gwt launches.

Did you import your project with mvn eclipse:eclipse into eclipse?
Maybe your runtime classpath still points to your local maven repo, but you already changed your eclipse project (my-game-core). Take a look at your eclipse classpath and make sure it only has the other project on it and not the jar from the repo.

Also check on the classpath tab in your run configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文