Reputation: 31
I'm trying to build a Maven plugin, that connects & talks to an Oracle XE DB.
My plugin builds without error, but when I try to execute it via Maven, I get at error that OracleDriver is missing.
[INFO] --- script-import-maven-plugin:1.0-SNAPSHOT:import (default-cli) @ TOLTAT-SQL-Migration ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.156 s
[INFO] Finished at: 2014-09-19T10:40:25+10:00
[INFO] Final Memory: 4M/490M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT:import (default-cli) on project TOLTAT-SQL-Migration: Execution default-cli of goal com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT:import failed: A required class was missing while executing com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT:import: oracle/jdbc/OracleDriver
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>com.tollgroup.tollonline.deploy:script-import-maven-plugin:1.0-SNAPSHOT
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/petertip/.m2/repository/com/tollgroup/tollonline/deploy/script-import-maven-plugin/1.0-SNAPSHOT/script-import-maven-plugin-1.0-SNAPSHOT.jar
[ERROR] urls[1] = file:/C:/Users/petertip/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: oracle.jdbc.OracleDriver
My Maven knowledge is limited, and my Java is fairly rusty.
I am not sure whether I need to put a dependency for ojdbc6 in the plugin's POM. It builds & installs happily without it. Adding it doesn't resolve my problem.
My JAVA is really simple at the moment, just trying to get it to talk to Oracle:
package au.com.toll.toltat.script_import_maven_plugin;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.OracleDriver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
* Goal which imports Stored Procedure scripts
*
* @goal import
*
* @phase process-sources
*/
public class ScriptImportMojo extends AbstractMojo
{
/**
* Location of the file.
* @parameter property="sql.update.directory"
* @required
*/
private String inputUpdateDirectory;
/**
* Location of the file.
* @parameter property="sql.rollback.directory"
* @required
*/
private String inputRollbackDirectory;
public void execute()
throws MojoExecutionException, MojoFailureException
{
try {
// register our JDBC driver
DriverManager.registerDriver (new OracleDriver());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The POM for the plugin is:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>script-import-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.oracle</groupId> -->
<!-- <artifactId>ojdbc6</artifactId> -->
<!-- <version>11.2.0.2.0</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
</project>
And the POM that's throwing the error is:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tollgroup.tollonline</groupId>
<artifactId>TOLTAT-SQL-Migration</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>script-import-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.2.0</version>
<scope>provided</scope>
</dependency -->
<dependency>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<sql.update.directory>update</sql.update.directory>
<sql.rollback.directory>rollback</sql.rollback.directory>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
</project>
Maven does suggest http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException as a possible solution. Unfortunately, that merely indicates that my JAR might be corrupt.
Since the ojdbc6.jar is stored in our Artifactory repository, and no one else is having issues with it, and I have deleted it & re-downloaded it, without any change, I don't think that's my problem.
The ojdbc6 jar exists in my \.m2\repository\com\oracle\ojdbc6\11.2.0.2.0
folder
Is it something as simple (and stupid on my behalf) as that OracleDriver is not in the ojdbc6.jar?
Thanks for any help you can offer,
Peter.
Upvotes: 0
Views: 1142
Reputation: 31
Fixed it...
I was importing oracle.jdbc.OracleDriver;
, when I should have been importing import oracle.jdbc.driver.OracleDriver;
.
Both are valid options, but only one is correct. :-(
Also had to change the scope of the ojdbc6 to runtime
in the plugin POM.
Upvotes: 1
Reputation: 14951
Add the dependency to the plugin config in the POM that is currently failing:
<build>
<plugins>
<plugin>
<groupId>com.tollgroup.tollonline.deploy</groupId>
<artifactId>script-import-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Upvotes: 2