执行自定义Maven插件时,必需的类缺少oracle / jdbc / OracleDriver

时间:2014-09-19 02:25:58

标签: oracle maven plugins jdbc

我正在尝试构建一个Maven插件,它可以连接&与Oracle XE DB进行对话。

我的插件构建没有错误,但是当我尝试通过Maven执行它时,我得到错误,OracleDriver丢失了。

[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

我的Maven知识有限,我的Java相当生疏。

我不确定是否需要在插件的POM中添加ojdbc6的依赖项。它建立和没有它安装愉快。添加它并不能解决我的问题。

我的JAVA目前非常简单,只是想让它与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();
        }
    }
}

插件的POM是:

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

抛出错误的POM是:

<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确实建议http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException作为可能的解决方案。不幸的是,这仅仅表明我的JAR可能已经腐败。

由于ojdbc6.jar存储在我们的Artifactory存储库中,并且没有其他人遇到问题,我已将其删除了。重新下载它,没有任何改变,我不认为这是我的问题。 ojdbc6 jar存在于我的\.m2\repository\com\oracle\ojdbc6\11.2.0.2.0文件夹

是否因为OracleDriver不在ojdbc6.jar中而变得简单(而且代表我很愚蠢)?

感谢您提供的任何帮助,

彼得。

2 个答案:

答案 0 :(得分:2)

将依赖项添加到当前失败的POM中的插件配置:

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

答案 1 :(得分:1)

修正了......

我导入oracle.jdbc.OracleDriver;时,我应该导入import oracle.jdbc.driver.OracleDriver;

两者都是有效的选项,但只有一个是正确的。 : - (

还必须在插件POM中将ojdbc6的范围更改为runtime