NoClassDefFoundError apache commons UrlValidator in GAE with eclipse

i am using the apache commons UrlValidator in one of my java files. the file compiles fine but whenever i run it, i get a NoClassDefFoundError for the UrlValidator class

i am using Google App Engine 1.7.5 with Eclipse Juno for JavaEE. i have included the the commons jar file in the build path as well as in the run config of my project under source but i still get the same error.

heres the code of my java file:

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);
}

}

and heres the error:

HTTP ERROR 500

Problem accessing /Share. Reason:

org/apache/commons/validator/routines/UrlValidator

Caused by:

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) 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: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.S 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) 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.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.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(WebApp Context.java:418) at 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$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.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) Caused by: java.lang.Cl assNotFoundException: 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.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) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 34 more Caused by:

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.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) 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) at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilte r.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.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:94) at 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) Powered by Jetty://

i have no idea as to whats causing this. Thanks for any help.

i added these three files: commons-validator-1.4.0.jar, commons-validator-1.4.0-javadoc.jar, and commons-validator-1.4.0-sources.jar. i added them to the project thorugh project properties -> java build path -> libraries -> add external jars. i added them to the run/debug settings under my project: run/debug -> -> source -> add


如果将这些文件添加到war / WEB-INF / lib中,会发生什么情况?

链接地址: http://www.djcxy.com/p/63574.html

上一篇: Google应用引擎

下一篇: NoClassDefFoundError apache commons UrlValidator在GAE中用eclipse