未找到驱动程序类

时间:2016-02-25 18:07:21

标签: java mysql maven

当我尝试清理构建时,我在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

我环顾四周并认为这可能是因为我的项目找不到我的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 / main / resources中的数据库属性文件:

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

我尝试手动添加mysql-connector-java-5.1.6作为我的maven项目中的依赖项。提前致谢

1 个答案:

答案 0 :(得分:0)

如果你看看&#34;用法&#34;下的sql-maven-plugin的主页。它清楚地表明你必须将你的驱动程序作为sql-maven-plugin的依赖项。您只是将其作为项目的依赖项。

如果您的项目需要这种依赖关系,那么这是一个不同的故事。