NoClassDefFoundError apache在GAE中使用eclipse来传递UrlValidator

时间:2013-03-17 06:01:17

标签: eclipse google-app-engine apache-commons noclassdeffounderror

我在我的一个java文件中使用apache commons UrlValidator。 该文件编译正常,但每当我运行它,我得到UrlValidator类的NoClassDefFoundError

我正在使用带有Eclipse Juno for JavaEE的Google App Engine 1.7.5。我已经在构建路径中包含了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 ERROR 500

访问/分享问题。原因是:

org/apache/commons/validator/routines/UrlValidator

引起:

java.lang.NoClassDefFoundError:org / apache / commons / validator / routines / 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)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在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)     在com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)     在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)     在com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.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)     在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)     在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)     在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)     在org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)     at 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)     在org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:582) 引起:java.lang.ClassNotFoundException:org.apache.commons.validator.routines.UrlValidator     在java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)     在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)     at java.security.AccessController.doPrivileged(Native Method)     在java.net.URLClassLoader.findClass(URLClassLoader.java:354)     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)     在com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213)     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)     ......还有34个 引起:

java.lang.ClassNotFoundException:org.apache.commons.validator.routines.UrlValidator     在java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)     在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)     at java.security.AccessController.doPrivileged(Native Method)     在java.net.URLClassLoader.findClass(URLClassLoader.java:354)     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)     在com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213)     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)     在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)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)     在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)     在com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)     在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)     在com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.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)     在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)     在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)     在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)     在org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)     at 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)     在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。 我将它们添加到项目项目属性 - &gt; java构建路径 - &gt;库 - &gt;添加外部罐子。 我将它们添加到我的项目下的运行/调试设置:run / debug - &gt; - &GT;来源 - &gt;添加

1 个答案:

答案 0 :(得分:2)

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