找不到数据库驱动程序:org.postgresql.Driver
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14501332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find database driver: org.postgresql.Driver
提问by user1338413
Im trying to change a project a bit, by upgrading it with Liquibase. Its a Java EE project. So im using the liquibase-maven-plugin.
我试图通过使用 Liquibase 升级它来稍微改变一个项目。它是一个 Java EE 项目。所以我使用 liquibase-maven-plugin。
So far i have in my pom.xml:
到目前为止,我的 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>
which already includes a Driver:
其中已经包含一个驱动程序:
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
the liquibase.properties file has the url, username, password, the changeLogFile-Path and the driver:
liquibase.properties 文件包含 url、用户名、密码、changeLogFile-Path 和驱动程序:
#liquibase.properties
driver: org.postgresql.Driver
But it does not have a classpath for the driver. Do I need the classpath as well?
但它没有驱动程序的类路径。我还需要类路径吗?
The changelog.xml has a simple changeset which creates a table, just to test liquibase for the beginning.
changelog.xml 有一个简单的变更集,它创建一个表,只是为了测试 liquibase 的开始。
But I dont come so far, because when I run the project with
但我没有走到那么远,因为当我运行项目时
mvn liquibase:update
Im getting this error:
我收到此错误:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:2.0.5:update (default-cli) on project PROJECT: Error setting up or running Liquibase: java.lang.RuntimeException: Cannot find database driver: org.postgresql.Driver
[错误] 无法执行目标 org.liquibase:liquibase-maven-plugin:2.0.5:update (default-cli) on project PROJECT:设置或运行 Liquibase 时出错:java.lang.RuntimeException:找不到数据库驱动程序:org .postgresql.Driver
I cant see the point.. The driver has been already been used before with the project. So why cant liquibase find it?
我看不出重点.. 驱动程序之前已经在项目中使用过。那么为什么 liquibase 找不到它呢?
EDIT
编辑
When i edit my configuration in the pom.xml by adding the driver tag it works:
当我通过添加驱动程序标记在 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>
before that my driver was specified in liquibase.properties, which should actually work as well.
在此之前,我的驱动程序是在 liquibase.properties 中指定的,它实际上也应该可以工作。
maybe someone can tell me how the liquibase.properties file should look like if i′d like to keep the driver in the properties file.
如果我想将驱动程序保留在属性文件中,也许有人可以告诉我 liquibase.properties 文件应该是什么样子。
回答by Barry Pitman
You have added the postgresql driver as a dependency of your webapp. But when maven plugins run, they have their own classpath, which is different to your webapp. So you need to include a dependency on the JDBC driver for the plugin itself (same applies to other plugins, e.g. jetty-maven-plugin):
您已将 postgresql 驱动程序添加为您的 web 应用程序的依赖项。但是当 maven 插件运行时,它们有自己的类路径,这与您的 web 应用程序不同。因此,您需要为插件本身包含对 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>
Edit:
编辑:
The problem was resolved by replacingdriver: org.postgresql.Driver
with driver=org.postgresql.Driver
in the liquibase.properties file.
问题是由替代解决driver: org.postgresql.Driver
与driver=org.postgresql.Driver
在liquibase.properties文件。
回答by Pruthviraj
Following plugin configuration worked for me.
以下插件配置对我有用。
<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>