Question

I am trying to build my pom.xml so that I can automatically create my database schema when running 'mvn install'. I'm using the "maven-cayenne-plugin" to do this. This is plugin is being called (at the integration-test phase), as I can see the output. But the mojo fails with the exception: (I used the -e and -X flag to see this).

java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver

(I get the same if I try and use the EmbeddedDriver and whether or not I include 'derbyclient' or simply 'derby' as my dependency).

Here's a pom.xml that should replicate the issue. I'm using MVN 3 on Windows. [ Apache Maven 3.0.4 (r1232337; 2012-01-17 08:44:56+0000) ]

<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.mycompany</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cayenne.plugins</groupId>
                <artifactId>maven-cayenne-modeler-plugin</artifactId>
                <version>3.2M1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.cayenne.plugins</groupId>
                <artifactId>maven-cayenne-plugin</artifactId>
                <version>3.2M1</version>
                <executions>
                    <execution>
                        <id>cgen</id>
                        <configuration>
                            <superPkg>com.mycompany.model.generated</superPkg>
                            <map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
                            <destDir>${project.build.sourceDirectory}</destDir>
                        </configuration>
                        <goals>
                            <goal>cgen</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cdbgen</id>
                        <configuration>
                            <map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
                            <driver>org.apache.derby.jdbc.ClientDriver</driver>
                            <url>jdbc:derby:memory:tracedb;create=true</url>
                            <username>test</username>
                        </configuration>
                        <goals>
                            <goal>cdbgen</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
<dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.10.1.1</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>
</project>

This also requires a valid cayenne "datamap.map.xml" file (in src/main/resources), here's one I made earlier:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
     project-version="6">
    <db-entity name="TEST">
        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
    </db-entity>
</data-map>

EDIT:

Adding more information.

The derbyclient-10.10.1.1.jar does contain the class 'org.apache.derby.jdbc.ClientDriver' (just expanded the JAR from Netbeans).

The -X flag seems to show that the CLASSPATH is correctly referencing the JAR:

[DEBUG]   (f) classpathElements = [<PROJECT-PATH>\mvn\target\classes, <HOME-DIR>\.m2\repository\org\apache\derby\derbyclient\10.10.1.1\derbyclient-10.10.1.1.jar]

SOLUTION:working pom.xml (see answer and my comment):

<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.mycompany</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cayenne.plugins</groupId>
                <artifactId>maven-cayenne-modeler-plugin</artifactId>
                <version>3.2M1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.cayenne.plugins</groupId>
                <artifactId>maven-cayenne-plugin</artifactId>
                <version>3.2M1</version>
<dependencies>
      <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.10.1.1</version>
      </dependency>
   </dependencies>
                <executions>
                    <execution>
                        <id>cgen</id>
                        <configuration>
                            <superPkg>com.mycompany.model.generated</superPkg>
                            <map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
                            <destDir>${project.build.sourceDirectory}</destDir>
                        </configuration>
                        <goals>
                            <goal>cgen</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cdbgen</id>
                <configuration>
                            <map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
                            <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
                            <url>jdbc:derby:memory:tracedb;create=true</url>
                            <username>test</username>
                        </configuration>
                        <goals>
                            <goal>cdbgen</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
<dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.10.1.1</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>
</project>
Était-ce utile?

La solution

To ensure that the Derby driver is available during plugin execution (vs during your code compilation), you need to add it as a dependency of the plugin itself:

<plugin>
   <groupId>org.apache.cayenne.plugins</groupId>
   <artifactId>maven-cayenne-plugin</artifactId>
   <version>3.2M1</version>
   <dependencies>
      <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>10.10.1.1</version>
      </dependency>
   </dependencies>
   ....
</plugin>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top