Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find database driver: org.postgresql.Driver

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.

So far i have in my 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
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.

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

I cant see the point.. The driver has been already been used before with the project. So why cant liquibase find it?

EDIT

When i edit my configuration in the pom.xml by adding the driver tag it works:

            <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.

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.

like image 553
user1338413 Avatar asked Jan 24 '13 12:01

user1338413


2 Answers

Edit:

The problem was resolved by replacing
driver: org.postgresql.Driver with driver=org.postgresql.Driver in the liquibase.properties file.


Original Answer:

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):

<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>
like image 101
Barry Pitman Avatar answered Oct 22 '22 02:10

Barry Pitman


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>
like image 32
Pruthviraj Avatar answered Oct 22 '22 00:10

Pruthviraj