Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - add .jar to Dynamic Web Project [duplicate]

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
    }
}

it throw the exception:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

in the line:

Class.forName("com.mysql.jdbc.Driver");

In the Build path of the dynamic web project I added the jar:

mysql-connector-java-5.1.21-bin.jar

I add snapshot of the folder , you can see where it is the required jar -

enter image description here

like image 547
URL87 Avatar asked Sep 11 '25 09:09

URL87


1 Answers

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).

like image 112
JB Nizet Avatar answered Sep 12 '25 22:09

JB Nizet