2016-02-25 64 views
0

當我嘗試清理構建時,我在netbeans中的Maven mysql項目中遇到錯誤。錯誤是:未找到驅動程序類

Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default) on project utopiaDatabase: Driver class not found: com.mysql.jdbc.Driver 

我環顧四周,估計這可能是因爲我的項目isn`t我找到使用mysql-connector-java的,但我把它加在我的POM文件的依賴,一切看起來不錯,你知道爲什麼它可能找不到它嗎?

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.eeu46f</groupId> 
<artifactId>utopiaDatabase</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>jar</packaging> 
<profiles> 
    <profile> 
     <id>hsql</id> 
     <dependencies> 
      <dependency> 
       <groupId>org.hsqldb</groupId> 
       <artifactId>hsqldb</artifactId> 
       <version>2.3.2</version> 
       <classifier>jdk6debug</classifier> 
      </dependency> 
     </dependencies> 
     <properties> 
      <jdbc.url>jdbc:hsqldb:mem:testDB</jdbc.url> 
      <jdbc.username>SA</jdbc.username> 
      <jdbc.password></jdbc.password> 
      <jdbc.driver>org.hsqldb.jdbc.JDBCDriver</jdbc.driver> 
     </properties> 
    </profile> 
    <profile> 
     <id>mysql</id> 
     <dependencies> 
      <dependency> 
       <groupId>mysql</groupId> 
       <artifactId>mysql-connector-java</artifactId> 
       <version>5.1.6</version> 
       <scope>runtime</scope> 
      </dependency> 
     </dependencies> 
     <properties> 
      <jdbc.url>jdbc:mysql:taken out for security</jdbc.url> 
      <jdbc.username>taken out for security</jdbc.username> 
      <jdbc.password>taken out for security</jdbc.password> 
      <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver> 
     </properties> 
    </profile> 
</profiles> 
<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-collections4</artifactId> 
     <version>4.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <version>2.3.2</version> 
     <classifier>jdk6debug</classifier> 
    </dependency> 
    <dependency> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>sql-maven-plugin</artifactId> 
     <version>1.5</version> 
    </dependency> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.6</version> 
    </dependency> 
</dependencies> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <maven.compiler.source>1.7</maven.compiler.source> 
    <maven.compiler.target>1.7</maven.compiler.target> 
</properties> 
<build> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>true</filtering> 
     </resource> 
    </resources> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>sql-maven-plugin</artifactId> 
      <version>1.5</version> 
      <configuration> 
       <driver>${jdbc.driver}</driver> 
       <url>${jdbc.url}</url> 
       <username>${jdbc.username}</username> 
       <password>${jdbc.password}</password> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>generate-test-resources</phase> 
        <goals> 
         <goal>execute</goal> 
        </goals> 
        <configuration> 
         <srcFiles> 
          <srcFile>src/test/resources/1-destroy.sql</srcFile> 
          <srcFile>src/test/resources/2-create.sql</srcFile> 
          <srcFile>src/test/resources/3-insert.sql</srcFile> 
         </srcFiles> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

<name>utopiaDatabase</name> 

數據庫屬性中的src文件/主/資源:

jdbc.url=${jdbc.url} 
jdbc.username=${jdbc.username} 
jdbc.password=${jdbc.password} 
jdbc.driver=${jdbc.driver} 

我曾嘗試添加MySQL的連接器的Java-5.1.6如手動也在我的maven項目中進行依賴。在此先感謝

+0

你是否激活了mysql配置文件? – 2016-02-25 18:11:46

+0

是的mysql配置文件被激活,其值得注意的是我有與hsql配置文件活動 – Defa1t

+0

[ClassNotFoundException com.mysql.jdbc.Driver](http://stackoverflow.com/q/1585811)相同的問題? – Tom

回答

0

如果您在「Usage」下查看sql-maven-plugin的主頁,它清楚地表明您必須將驅動程序作爲對sql-maven-plugin的依賴項。您只將它作爲項目的依賴項。

如果您的項目需要這種依賴關係,那麼這是一個不同的故事。

相關問題