MAVEN introduces the JDBC package with POM under Web Engineering, and the runtime still displays the ClassNotFoundException method

Source: Internet
Author: User
Tags tomcat server

Today in company training, do a simple servlet program that requires the use of Tomcat's Web project.

I first created the MAVEN project, right-added the Web project properties, and happily started writing the servlet, which had to do with the third-party JDBC driver, so I introduced it with Pom.xml, which was introduced as follows:

 <Dependency>          <groupId>Mysql</groupId>          <Artifactid>Mysql-connector-java</Artifactid>          <version>5.1.25</version> </Dependency>

After Reimport, it is true that the JDBC package has been introduced, and writing a single Java code with the main function can also be successfully connected. Put this part of the code into the Web project, open the Tomcat server running in the browser Leng can not be removed, and then troubleshoot the discovery is unable to load the JDBC class.

So the question comes, I have introduced the package, why is not it?

After the degree of mom Google search combined with their own understanding, and finally found the reason:

The Tomcat project is for the introduction of packet-first lookup (personally think is only looking for) Web-inf/lib under the introduction package, that is, the Tomcat server found that this package is not in the default LIB, will look for the Lib folder under the jar file, rather than to find the package that the Pom introduced, In fact, when you look at the document can be found that the two put into the package is different AH. (each folder is useful for my follow-up.)

Workaround: Build the Lib folder under Web-inf and throw the jar package in.

After testing, this method is possible ~ and colleagues to discuss, said that I created a project method has problems resulting in the inability to find the pom introduction package, I will study the study.

MAVEN introduces the JDBC package with POM under Web Engineering, and the runtime still displays the ClassNotFoundException method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.