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