2014-09-19 69 views
0

我試圖構建一個Maven插件,它將連接&會話連接到Oracle XE DB。當執行自定義Maven插件時,所需的類缺少oracle/jdbc/OracleDriver

我的插件生成沒有錯誤,但是當我嘗試通過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中那樣簡單(而且我的笨蛋)?

謝謝你可以提供的任何幫助,

Peter。

+1

一位同事做它爲我工作,但是,只有更換'後DriverManager.registerDriver(新一個OracleDriver()); ''用'Class.forName(「oracle.jdbc.driver.OracleDriver」);' 我遇到的問題是,它完全飛行在面對doco http://docs.oracle.com/cd /E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html,它表示使用Class.forName不適用於所有情況。 – 2014-09-19 04:25:50

回答

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

固定它...

我進口oracle.jdbc.OracleDriver;,當我一直在進口import oracle.jdbc.driver.OracleDriver;

兩者都是有效的選項,但只有一個是正確的。 :-(

也不得不在ojdbc6的範圍更改爲runtime在插件POM

相關問題