尝试引用外部 jar 文件时出现 NoClassDefFoundError

发布于 2024-10-16 11:56:51 字数 1144 浏览 2 评论 0原文

我有一些第 3 方 jar 文件,我想在我的 tomcat Web 应用程序中引用它们。我将此行添加到 catalina.properties:shared.loader=/home/ollie/dev/java/googleapi_samples/gdata/java/lib/*.jar

我仍然收到此错误:

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/google/gdata/util/ServiceException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

我验证了 com.google. gdata.util.ServiceException 位于 gdata-core-1.0.jar 文件中,该文件位于目录:

/home/ollie/dev/java/googleapi_samples/gdata/java/lib

修改catalina.properties后,我确实反弹了tomcat。

更新1: 我尝试将 gdata-core-1.0.jar 文件复制到 /var/lib/tomcat6/webapp/examples/WEB-INF/lib 作为测试,但这也没有解决问题。

更新2: 当我将 jar 文件直接复制到 WEB-INF/lib 目录中时,它实际上确实有效。我必须解决一个权限问题。但当我使用shared.loader设置时它仍然不起作用。我再次确认路径是正确的。

I have some 3rd party jar files that I want to reference in my tomcat web application. I added this line to catalina.properties:

shared.loader=/home/ollie/dev/java/googleapi_samples/gdata/java/lib/*.jar

but I'm still getting this error:

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/google/gdata/util/ServiceException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I verified that the com.google.gdata.util.ServiceException is in the gdata-core-1.0.jar file which is in the directory:

/home/ollie/dev/java/googleapi_samples/gdata/java/lib

I did bounce tomcat after I modified catalina.properties.

Update 1:
I tried copying the gdata-core-1.0.jar file into
/var/lib/tomcat6/webapp/examples/WEB-INF/lib
as a test but that didn't fix the problem either.

Update 2:
It actually does work when I copy the jar file directly into the WEB-INF/lib directory. There was a permissions issue that I had to resolve. But it's still not working when I use the shared.loader setting. I reconfirmed that the path is correct.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮年 2024-10-23 11:56:51

我不确定这一点,但有两个潜在的原因:

  1. shared.loader 中指定的路径存在文件权限问题,可能与您摆弄<时遇到的问题相同code>/WEB-INF/lib。

  2. 您没有编辑您认为正在使用的 Tomcat 实例的 catalina.properties 文件。例如,如果您从 Eclipse 内部运行 Tomcat,则需要确保已将 Eclipse 配置为接管 Tomcat,而不是使用工作区元数据(其中 Eclispe 实际上基于 Tomcat conf 文件的副本运行)。为此,请取消部署/删除所有项目,双击 Tomcat 条目并在服务器位置部分中选择使用 Tomcat 安装。然后将使用Tomcat自己的/conf文件夹中的配置文件。否则,您需要在 Eclipse 工作区的 Servers 项目中编辑它。

I'm not sure about this one, but there are two potential causes:

  1. There's a file permission issue in path as specified in shared.loader, probably the same as you had when fiddling with /WEB-INF/lib.

  2. You aren't editing the catalina.properties file of the Tomcat instance you think you're using. For example, if you're running Tomcat from inside Eclipse, you need to ensure that you've configured Eclipse to take over Tomcat rather than using workspace metadata (where Eclispe actually runs based on a copy of Tomcat conf files). To do this, undeploy/remove all projects, doubleclick Tomcat entry and select Use Tomcat installation in Server locations section. Then the config files in Tomcat's own /conf folder will be used. Otherwise you need to edit it in Servers project of Eclipse workspace.

北凤男飞 2024-10-23 11:56:51

您可以尝试在路径前添加 file:// 前缀吗?

shared.loader=file:///home/ollie/dev/java/googleapi_samples/gdata/java/lib/*.jar

Can you try prefixing the path with file://?

shared.loader=file:///home/ollie/dev/java/googleapi_samples/gdata/java/lib/*.jar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文