在localhost调试我的webapp时,一切运行良好,但是当将它部署到服务器(Microsoft,OS:Ubuntu14.04 tomcat7+apache )时,无法找到jcaptcha servlet,它会抛出异常为"java.lang.NoClassDefFoundError:未能初始化类“。
type Exception report
message Servlet execution threw an exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause
java.lang.NoClassDefFoundError: Could not initialize class com.tjw.hrmanage.util.jcaptcha.CaptchaServiceSingleton
com.tjw.hrmanage.util.jcaptcha.JcaptchaServlet.doGet(JcaptchaServlet.java:40)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.52 (Ubuntu) logs.发布于 2016-05-04 05:20:05
我将jdk版本从openjdk7更改为java-8-oracle,并重新启动tomcat,然后一切运行良好,非常感谢您的回答。
发布于 2016-05-03 07:16:45
这是因为您的应用程序在ubuntu中找不到相应的jar文件。您可以将该类的jar文件添加到/lib中,并在eclipse中的“构建路径”中添加对此jar的引用,然后重新部署您的项目以再次蔚蓝。
发布于 2016-05-03 10:13:57
正如我所知道的,有三个常见的原因会导致这个错误。
CLASSPATH中,也没有确切的方法来了解它,但是很多时候,您只需查看一下打印System.getProperty("java.classpath"),它就会打印类路径,至少可以了解实际的运行时类路径。-classpath选项来运行您认为可以工作的类路径,如果它工作正常,那么这是一个明显的简短迹象,表明有人正在覆盖java类路径。根据我的经验,我认为你的问题符合第一个案例。请检查您的代码和参考库。
https://stackoverflow.com/questions/36983033
复制相似问题