我目前正在开发名为Force.com for Google App Engine for Java: Getting Started
的SalesForce.com教程我已经安装了Google Eclipse插件,下载了库并将它们安装到构建路径,然后输入了“Hello World App”(如教程页面所示):
package com.force;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.*;
import java.util.logging.*;
import com.sforce.ws.*;
import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.SObject;
@SuppressWarnings("serial")
public class HelloWorldServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(HelloWorldServlet.class.getName());
private String username = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private String password = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private PartnerConnection connection;
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
resp.getWriter().println("Hello, world. this is a test2");
PrintWriter t = resp.getWriter();
getConnection( t, req);
if ( connection == null ) { return; }
QueryResult result = null;
try {
result = connection.query( "select id, name, phone from Account order by LastModifiedDate desc limit 10 ");
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (SObject account : result.getRecords()) {
t.println("<li>"+ (String)account.getField("Name") + "</li>");
}
}
void getConnection(PrintWriter out, HttpServletRequest req) {
try {
// build up a ConnectorConfig from a sid
String sessionid = req.getParameter("sid");
String serverurl = req.getParameter("srv");
if ( connection == null ) {
out.println("<p>new connection needed</p>");
// login to the Force.com Platform
ConnectorConfig config = new ConnectorConfig();
if ( sessionid != null && serverurl != null) {
config.setServiceEndpoint(serverurl);
config.setSessionId(sessionid);
config.setManualLogin(false);
out.println("using session from query string");
} else {
config.setUsername(username);
config.setPassword(password);
}
connection = Connector.newConnection(config);
out.println( connection.getConfig().getSessionId() );
out.println( connection.getConfig().getServiceEndpoint() );
} else {
out.println("<p> reuse existing connection");
out.println( connection.getConfig().getSessionId() );
}
log.warning("Connection SID " +connection.getConfig().getSessionId());
} catch ( ConnectionException ce) {
log.warning("ConnectionException " +ce.getMessage());
out.println( ce.getMessage() + " s " + ce.getClass() );
}
}
}
当我将应用程序作为“Web应用程序”运行时,我在Web浏览器中获得以下内容:
HTTP ERROR 500
Problem accessing /sfdc_gae_tutorials/hello2. Reason:
Could not initialize class com.sforce.ws.ConnectorConfig
Caused by:
java.lang.NoClassDefFoundError: Could not initialize class com.sforce.ws.ConnectorConfig
at hu.flux.salesforce.hello.HelloWorld2Servlet.getConnection(HelloWorld2Servlet.java:57)
at hu.flux.salesforce.hello.HelloWorld2Servlet.doGet(HelloWorld2Servlet.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
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:122)
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.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
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.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
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)
Powered by Jetty://
知道为什么没有进行初始化,出现了什么问题,和/或如何修复它?
答案 0 :(得分:1)
您没有将WSC添加到Eclipse项目的类路径中。从你发布的教程:
这些说明的唯一问题是你应该使用wsc-gae - * .jar,而不仅仅是常规的wsc.jar。
答案 1 :(得分:0)
我也遇到了这个问题,尽管你在项目构建路径中添加了wsc.jar和enterprise.jar,但仍然会抛出“NoClassDefFoundError”。 但是,一旦我将这些JAR复制到WEB_INF - &gt; lib,它神奇地起作用。 不知道为什么。
ANyone请解释为什么会这样。