[英]Maven dependency (MySQL-Connector) not found during testing phase
我正在尝试使用Maven和Java设计应用程序。 它的一部分连接到MySQL数据库。 为此,我使用Class.forName("com.mysql.jdbc.Driver");
。 我还mysql-connector-java' dependency to my pom.xml. However when I run
添加了mysql-connector-java' dependency to my pom.xml. However when I run
mysql-connector-java' dependency to my pom.xml. However when I run
mvn测试mysql-connector-java' dependency to my pom.xml. However when I run
I receive the following error when the line
连接= DriverManager.getConnection(“ jdbc:mysql // kritsit.ddns.net:CaseTracker”,用户名和密码) I receive the following error when the line
:
Running com.kritsit.casetracker.server.domain.services.DatabasePersistenceTest
java.sql.SQLException: No suitable driver found for jdbc:mysql//kritsit.ddns.net:CaseTracker
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.kritsit.casetracker.server.domain.services.DatabasePersistence.open(DatabasePersistence.java:26)
at com.kritsit.casetracker.server.domain.services.DatabasePersistenceTest.testOpen(DatabasePersistenceTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at junit.framework.TestCase.runTest(TestCase.java:154)
...
我的maven pom.xml如下所示(省略号为简洁起见显示了一些遗漏的块:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kritsit.casetracker</groupId>
<artifactId>server</artifactId>
<packaging>jar</packaging>
<version>0.1a-SNAPSHOT</version>
<name>CaseTracker Server</name>
...
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.21</version>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteRelease>true</overWriteRelease>
</configuration>
</execution>
</executions>
</plugin>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.kritsit.casetracker.server.CaseTrackerServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
...
<plugin>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</plugin>
....
</plugins>
</build>
...
我该如何解决找不到合适的驱动程序的问题?
您的JDBC URI是否正确? 'mysql'之后可能缺少冒号。 尝试
jdbc:mysql://kritsit.ddns.net:CaseTracker
而不是jdbc:mysql//kritsit.ddns.net:CaseTracker
(来自MySQL文档的 URI语法)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.