Eclipse - 将.jar添加到Dynamic Web Project [英] Eclipse - add .jar to Dynamic Web Project
问题描述
当我在 servlet
内的eclipse Dynamic Web Project
中使用以下代码时,如下所示:
When I use the follow code in eclipse Dynamic Web Project
inside servlet
, like this :
@WebServlet("/CreateCustomerServlet")
public class CreateCustomerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private void test() throws SQLException, ClassNotFoundException {
// use the JAR ...
Class.forName("com.mysql.jdbc.Driver");//here the exception
}
}
它抛出异常:
java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
在行中:
Class.forName(com.mysql.jdbc.Driver);
在动态网络项目的构建路径中,我添加了jar:
In the Build path of the dynamic web project I added the jar:
mysql-connector-java-5.1.21-bin.jar
我添加文件夹的快照,你可以看到它的位置必需的jar -
I add snapshot of the folder , you can see where it is the required jar -
推荐答案
如截图所示,mysql jar不会出现在 Web App Libraries 节点下。将jar粘贴到 WebContent / WEB-INF / lib
中,它将自动添加到构建路径和
中webapp的运行时类路径(它将出现在 Web App Libraries 下)。
As your screenshot shows, the mysql jar doesn't appear under the Web App Libraries node. Paste the jar in WebContent/WEB-INF/lib
, and it will be automatically added to the build path and
to the runtime classpath of the webapp (and it will appear under Web App Libraries).
这篇关于Eclipse - 将.jar添加到Dynamic Web Project的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!