我有一个包含函数的java 文件。它使用一些外部 API。(我添加了外部 jar 文件)。
现在我有一个 servlet 并在 doGet() 中,想要调用上面 java 类的函数。
我是否必须在 servlet 中编写 API 的所有导入语句?
因为我在 servlet 未运行时收到错误。
错误 HTTP 状态 500 - Servlet 执行引发异常
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
root cause
java.lang.NoClassDefFoundError: jxl/read/biff/BiffException
hello.hello.doGet(hello.java:77)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.ClassNotFoundException: jxl.read.biff.BiffException
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
hello.hello.doGet(hello.java:77)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
最佳答案
我将外部 JAR 文件复制到 Tomcat 7.0\lib 中,它解决了问题。
从 http://scn.sap.com/thread/1410297 得到这个想法
这是正确的解决方案吗? 也就是说,每当我们必须在 servlet 中使用外部 API 时,我们都必须配置构建路径添加 JAR,并将 JAR 复制到 tomcat\lib 文件夹中?
关于java - Servlet-调用java函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15608776/