Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

I got this exception:

java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

I use jtds-1.2.2. I tried add jar or add external jar. I also do:

    String driver = "net.sourceforge.jtds.jdbc.Driver";

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) { 
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  

I did the same in java project and everything works good. But doing this in jsf project I get this exception. Why ?

like image 710
Aram Gevorgyan Avatar asked Sep 13 '26 14:09

Aram Gevorgyan


1 Answers

The libraries used by a web application at runtime are all the jars placed in the WEB-INF/lib directory of the deployed webapp. Adding the library in the classpath used to compile the webapp doesn't make it automatically available at runtime.

If you're using Eclipse, just drop the jar in WebContent/WEB-INF/lib, and it will be automatically added to the build path (i.e. the classpath used to compile the app), and also be part of the deployed webapp, and thus be available at runtime.

like image 66
JB Nizet Avatar answered Sep 16 '26 02:09

JB Nizet