I was revisiting how to connect to a database using JDBC in Eclipse .
I created a project ( Dynamic Web Project ) and added the relevant JAR file for database connection in the external JAR files section ( Project Java Build Path --> Libraries --> Add external jars ). But still I was getting the java.lang.ClassNotFoundException
.
I went through other posts and found a solution. Someone suggested to copy the JAR file into the WEB-INF/lib folder of the project. I did that and it worked.
Is adding external files like we used to on eclipse still relevant?
Also, I keep getting this caution sign on the projects ( Dynamic Web Projects ) to which I add external JARs.
The same thing is no problem when working on normal java projects.
My eclipse version is Luna, Java version is 8 and Apache version is 7.
What you had done allowed Eclipse to resolve the classes during development but not for deployment.
Since you're building a servlet you have to set up the project in a way that will successfully deploy as a servlet. Moving the jar to WEB-INF/lib works because all the jars in that directory will be on the default classpath for the servlet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.