是否有一种特定的方法可以将库添加到tomcat而无需将其嵌入到每个webapp中?在目录
下/usr/share/tomcat7/lib
我已经放置了主mongodb驱动程序,它允许我部署war文件而不会发现类def def异常,但是当尝试连接到servlet时会发生以下错误:
Caused by: java.lang.NoClassDefFoundError: Lcom/mongodb/MongoClient;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2509)
at java.lang.Class.getDeclaredFields(Class.java:1819)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:87)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:382)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:858)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:346)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5209)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 27 more
Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoClient
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1712)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1557)
... 41 more
与MongoClient一起出现:
@WebServlet(urlPatterns = {"/login"}, loadOnStartup = 1)
public class LoginServlet extends HttpServlet {
private static MongoClient mongoClient = new MongoClient();
public LoginServlet() {
super();
}
}
这不是安装跨Web应用程序库的正确方法吗?