【问题标题】:Cannot find database driver: org.postgresql.Driver找不到数据库驱动程序:org.postgresql.Driver
【发布时间】:2013-01-08 05:00:01
【问题描述】:

我正在尝试通过使用 Liquibase 升级项目来稍微改变项目。它是一个 Java EE 项目。所以我使用的是 liquibase-maven-plugin。

到目前为止,我的 pom.xml 中有:

            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>2.0.5</version>
                <configuration>
                    <propertyFileWillOverride>true</propertyFileWillOverride>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                    <changeLogFile>src/main/resources/changelogs/changelog.xml</changeLogFile>
                </configuration>
                <executions>
                    <execution>
                        <!--  Another Error: plugin execution not covered by lifecycle configuration..-->
                        <!-- <phase>process-resources</phase> <goals> <goal>update</goal> </goals> -->
                    </execution>
                </executions>
            </plugin>

其中已经包含一个驱动程序:

        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901-1.jdbc4</version>
        </dependency>

liquibase.properties 文件包含 url、用户名、密码、changeLogFile-Path 和驱动程序:

#liquibase.properties
driver: org.postgresql.Driver

但它没有驱动程序的类路径。我也需要类路径吗?

changelog.xml 有一个简单的变更集,它创建一个表,只是为了测试 liquibase 的开始。

但我没有走这么远,因为当我运行项目时

mvn liquibase:update

我收到此错误:

[错误] 无法在项目项目上执行目标 org.liquibase:liquibase-maven-plugin:2.0.5:update (default-cli):设置或运行 Liquibase 时出错:java.lang.RuntimeException:找不到数据库驱动:org.postgresql.Driver

我看不懂。。该驱动程序之前已经在项目中使用过。那为什么 liquibase 找不到呢?

编辑

当我通过添加驱动程序标签在 pom.xml 中编辑我的配置时:

            <configuration>
                <propertyFileWillOverride>true</propertyFileWillOverride>
                <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                <changeLogFile>src/main/resources/changelogs/changelog.xml</changeLogFile>
                <driver>org.postgresql.Driver</driver>
            </configuration>

在 liquibase.properties 中指定我的驱动程序之前,它实际上应该也可以工作。

如果我想将驱动程序保留在属性文件中,也许有人可以告诉我 liquibase.properties 文件的外观。

【问题讨论】:

    标签: postgresql maven liquibase


    【解决方案1】:

    编辑:

    通过在 liquibase.properties 文件中将driver: org.postgresql.Driver 替换为driver=org.postgresql.Driver 解决了问题。


    原答案:

    您已将 postgresql 驱动程序添加为您的 web 应用程序的依赖项。但是当 maven 插件运行时,它们有自己的类路径,这与你的 webapp 不同。因此,您需要为插件本身包含对 JDBC 驱动程序的依赖(同样适用于其他插件,例如 jetty-maven-plugin):

    <plugin>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-maven-plugin</artifactId>
        <version>2.0.5</version>
        <configuration>
            <propertyFileWillOverride>true</propertyFileWillOverride>
            <propertyFile>src/main/resources/liquibase.properties</propertyFile>
            <changeLogFile>src/main/resources/changelogs/changelog.xml</changeLogFile>
        </configuration>
        <executions>
            <execution>
                <!--  Another Error: plugin execution not covered by lifecycle configuration..-->
                <!-- <phase>process-resources</phase> <goals> <goal>update</goal> </goals> -->
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.1-901-1.jdbc4</version>
            </dependency>
        </dependencies>
    </plugin>
    

    【讨论】:

    • 不,这不是问题。即使我第二次添加错误仍然出现。不过谢谢你的建议。
    • 奇怪,我刚刚使用属性文件尝试了您的示例,它为我选择了驱动程序(即使没有在插件中指定对 postgres 的依赖)。也许尝试从本地 maven 存储库中删除 postgres JAR 和 liquibase 插件,以便重新下载?还可以尝试使用“=”driver=org.postgresql.Driver 指定驱动程序。否则我没有想法,对不起!
    • 谢谢!!!!当某些东西有效或无效时,我真的很烦,我不明白为什么。这只是简单的":",而不是driver=org.postgresql.Driver 中的"="。再次感谢
    【解决方案2】:

    以下插件配置对我有用。

             <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>update</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-25
      • 1970-01-01
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 1970-01-01
      相关资源
      最近更新 更多