Java ファイルの 1 つで apache commons UrlValidator を使用しています。ファイルは正常にコンパイルされますが、実行するたびに、UrlValidator クラスの NoClassDefFoundError が発生します
JavaEE用のEclipse JunoでGoogle App Engine 1.7.5を使用しています。コモンズ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
/Share へのアクセスに問題があります。理由:
org/apache/commons/validator/routines/UrlValidator
のせいで:
java.lang.NoClassDefFoundError: org/apache/commons/validator/routines/UrlValidator at com.serv.servshare.Share.service(Share.java:41) at 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) で org. 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$ org.mortbay.jetty.servlet の com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34) の CachedChain.doFilter(ServletHandler.java:1157)。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) com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 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 .BackendServersFilter.doFilter(BackendServersFilter.java:97) at 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) で 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) com. google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at com.google.appengine.tools.development.JettyContainerService$ org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) の ApiProxyHandler.handle(JettyContainerService.java:409) org.mortbay.jetty.Server.handle(Server.java:326) org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) で org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) で org.mortbay.jetty.HttpParser.parseNext(HttpParser) .java:547) で org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) で org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) で org.mortbay.io.nio.SelectChannelEndPoint. run(SelectChannelEndPoint.java:409) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 原因: java.lang.ClassNotFoundException: org.apache.commons.validator.routines.UrlValidator at java. net.URLClassLoader$1.run(URLClassLoader.java:366) で java.net.URLClassLoader$1.run(URLClassLoader.java:355) で java.security.AccessController.doPrivileged(Native Method) で java.net.URLClassLoader.findClass(URLClassLoader.java:354) で java.lang.ClassLoader.loadClass(ClassLoader.java:423) com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213) で java .lang.ClassLoader.loadClass(ClassLoader.java:356) ... 34 以上 原因:
java.lang.ClassNotFoundException: org.apache.commons.validator.routines.UrlValidator at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.net.URLClassLoader$1.run(URLClassLoader.java:366) java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at com.google.appengine.tools. development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213) で java.lang.ClassLoader.loadClass(ClassLoader.java:356) com.serv.servshare.Share.service(Share.java:41) で 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.com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java: 123) org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) で com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34) で 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) com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) 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) at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97) at 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) 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) の 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) で org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) で 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) で org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) で 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 の 3 つのファイルを追加しました。私はそれらをプロジェクトのプロパティに追加しました - > Javaビルドパス - >ライブラリ - >外部jarを追加します。プロジェクトの下の実行/デバッグ設定にそれらを追加しました:実行/デバッグ->->ソース->追加