Eclipse - 将.jar添加到Dynamic Web Project [英] Eclipse - add .jar to Dynamic Web Project

查看:129
本文介绍了Eclipse - 将.jar添加到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆