我正在使用GWT2.6。在我的gwt服务器端,我试图实例化一个来自另一个eclipse项目的类。我将该项目添加到我的" Java Build Path"中。但是我仍然遇到java.lang.NoClassDefFoundError
问题。
我的代码和错误消息粘贴在下面。
Server: initialize and run
Jan 22, 2015 5:53:22 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List com.algorithmics.mdc.client.OnboardingToolService.getProducts()' threw an unexpected exception: java.lang.NoClassDefFoundError: com/algorithmics/datamart/dmob/app/DMOBApp
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:389)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:265)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:305)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.NoClassDefFoundError: com/algorithmics/datamart/dmob/app/DMOBApp
at com.algorithmics.mdc.server.OnboardingToolServiceImpl.getProducts(OnboardingToolServiceImpl.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 40 more
Caused by: java.lang.ClassNotFoundException: com.algorithmics.datamart.dmob.app.DMOBApp
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:216)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 47 more
我的代码:
public class OnboardingToolServiceImpl extends RemoteServiceServlet implements OnboardingToolService {
private String[] dmobArgs;
private void initializeDmob(){
dmobArgs = new String[]{"-U", "xx", "-P", "xx1234", "-S", "default", "-R", "suite-test", "-c", "c:\\xx\\xx\\xx\\cfg\\ConfigServer.cfg", "-o", "list"};
}
@Override
public List<ProductDefinition> getProducts() {
System.out.println("Server: dmobArgs");
DMOBApp.main(dmobArgs); //dmobArgs
System.out.println("Server: done");
List list = new LinkedList();
ProductDefinition stock = new ProductDefinition("stock","xx","aa","","","","");
ProductDefinition cash = new ProductDefinition("cash","xx","aa","","","","");
ProductDefinition bond = new ProductDefinition("bond","xx","aa","","","","");
ProductDefinition stock1 = new ProductDefinition("stock1","xx","aa","","","","");
ProductDefinition stock2 = new ProductDefinition("stock2","xx","aa","","","","");
ProductDefinition cash1 = new ProductDefinition("cash1","xx","aa","","","","");
list.add(stock);
list.add(cash);
list.add(bond);
return list;
}
}
答案 0 :(得分:2)
将它添加到构建路径是不够的。您还必须将其添加到/WEB-INF/lib
文件夹。否则,它将无法在服务器端使用。
如果您使用Eclipse,请选择项目并查看“问题”选项卡。您应该在那里看到一条消息,即服务器上的资源不可用。右键单击此消息,然后选择&#34;快速修复&#34;。选择&#34;复制...&#34;选项。
答案 1 :(得分:1)
您不需要在war目录中随时拥有此libs的副本。 在我的Ant脚本中,我创建了一个目标,用于在战争编译之前复制所有必需的库。
示例:强>
<target name="copy-server-libs" >
<copy file="lib/server/guice-3.0.jar" tofile="war/WEB_INF/lib/guice-3.0.jar"
</target>