NoClassDefFoundError apache commons UrlValidator在GAE中用eclipse
我在我的一个java文件中使用apache commons UrlValidator。 该文件编译罚款,但每当我运行它,我得到了UrlValidator类的NoClassDefFoundError
我正在使用Google App Engine 1.7.5和Eclipse Juno for JavaEE。 我已经将commons jar文件包含在构建路径以及源代码下的项目运行配置中,但我仍然得到相同的错误。
继承人我的Java文件的代码:
package com.serv.servshare;
import java.io.*;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.*;
import javax.servlet.http.*;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import org.apache.commons.validator.routines.UrlValidator;
public class Share extends HttpServlet implements Servlet{
private static final long serialVersionUID = 1L;
DatastoreService ds;
String link,email,msgBody,title,name;
String[] schemes={"https","http","ftp"};
UrlValidator urlValidator;
boolean valid;
Query q;
PrintWriter out;
PreparedQuery pq;
Properties props;
Session session;
Message msg;
public void service(ServletRequest req, ServletResponse res)throws ServletException,IOException{
title=req.getParameter("title").toString();
link=req.getParameter("link").toString();
//Instantiate UrlValidator
urlValidator = new UrlValidator(schemes);
out=res.getWriter();
//Validate URL
if (urlValidator.isValid(link)) {
valid=true;
}
else {
valid=false;
}
if(valid){
try{
ds=DatastoreServiceFactory.getDatastoreService();
q=new Query("email");
pq=ds.prepare(q);
//Query database to get all email ids
for(Entity result : pq.asIterable()){
email=result.getProperty("email").toString();
name=result.getProperty("name").toString();
//Instantiating the email prerequisites
props=new Properties();
session=Session.getDefaultInstance(props, null);
msgBody=link;
msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("webmaster@servshare.appspotmail.com", "WebMaster@ServShare"));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(email, name));
msg.setSubject(title);
msg.setText(msgBody);
//Sending out the uploaded link to all subscribers
Transport.send(msg);
out.println("<html><head><title>ServShare</title><meta http-equiv="refresh" content="3; URL=index.jsp"></head><body>Email sent! You will be redirected to the home page shortly.</body></html>");
}
}
catch(Exception e){
out.println("<html><body>An error was encountered while processing your request. Please go back and try again");
e.printStackTrace();
}
}
else{
out.println("<html><head><title>ServShare</title><meta http-equiv="refresh" content="3; URL=index.jsp"></head><body>The entered URL is not valid. You will be redirected to the home page shortly.</body></html>");
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException{
service(req,res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException{
service(req,res);
}
}
并继承错误:
HTTP错误500
访问/共享问题。 原因:
org/apache/commons/validator/routines/UrlValidator
引起:
java.lang.NoClassDefFoundError:组织/阿帕奇/公地/验证/例程/ UrlValidator在com.serv.servshare.Share.service(Share.java:41)在org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java :511)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1166)在com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)的组织。 mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)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),位于org.mortbay.jetty.servlet.S的com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61) ervletHandler $ 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)在com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)在com.google .appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)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.servlet.SessionHandler.handle(SessionHandler.java:182)at org.mortbay。org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)。 jetty.handler.ContextHandler.handle(ContextHandler.java:765)at org.mortbay.jetty.webapp.WebAppContext.handle(WebApp Context.java:418)在com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)在com.google .appengine.tools.development.JettyContainerService $ ApiProxyHandler.handle(JettyContainerService.java:409)at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)at org.mortbay.jetty.Server.handle(Server .java:326)at org.mortbay.jetty.HttpParser上org.mortbay.jetty.HttpConnection $ RequestHandler.headerComplete(HttpConnection.java:923)处的org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)。 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)引起:java.lang.Cl assNotFoundException:java.net.URLClassLoader上的org.apache.commons.validator.routines.UrlValidator $ 1.run(URLClassLoader.java:366)位于java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)at java.security。访问com.google.appengine.tools.development.IsolatedAppClassLoader上的java.net.URLClassLoader.findClass(URLClassLoader.java:354)处的java.lang.ClassLoader.loadClass(ClassLoader.java:423)处的AccessController.doPrivileged(Native Method)。 loadClass(IsolatedAppClassLoader.java:213)在java.lang.ClassLoader.loadClass(ClassLoader.java:356)... 34更多引起:
java.lang.ClassNotFoundException:java.net.URLClassLoader中的org.apache.commons.validator.routines.UrlValidator $ 1.run(URLClassLoader.java:366)at java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)at java.lang.ClassLoader.loadClass(ClassLoader.java:423),com.google.appengine.tools上的java.net.URLClassLoader.findClass(URLClassLoader.java:354)上的java.security.AccessController.doPrivileged(Native Method)。 development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213)at java.lang.ClassLoader.loadClass(ClassLoader.java:356)at com.serv.servshare.Share.service(Share.java:41)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.ResponseRewrite rFilter.doFilter(ResponseRewriterFilter.java:123)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:61)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 )在com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilte r.java:97)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)在org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)在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)在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)在com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)在org.mortbay.jetty。 handler.HandlerWrapper.handle(HandlerWrapper.java:152)at com.google.appengine.tools.development.JettyContainerService $ ApiProxyHandler.handle(JettyContainerService.java:409)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.mor tbay.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)由Jetty提供技术支持://
我不知道这是什么原因造成的。 谢谢你的帮助。
我添加了这三个文件:commons-validator-1.4.0.jar,commons-validator-1.4.0-javadoc.jar和commons-validator-1.4.0-sources.jar。 我将它们添加到项目的项目属性 - > java build path - > libraries - >添加外部jar。 我将它们添加到我的项目下的运行/调试设置中:运行/调试 - > - >源代码 - >添加
如果将这些文件添加到war / WEB-INF / lib中,会发生什么情况?
链接地址: http://www.djcxy.com/p/63573.html上一篇: NoClassDefFoundError apache commons UrlValidator in GAE with eclipse
下一篇: ResteasyBootstrap