2015-02-06 51 views
0

我正在嘗試編寫一個maven腳本,它使用sql-maven-plugin刪除並重新創建Oracle TimesTen數據庫,然後使用dbdeploy應用一些數據庫遷移腳本在預集成測試階段。多個Maven插件依賴關係 - 本地庫已經加載到另一個類加載器

這些插件,都需要使用它當然不能由不同的類加載器加載,產生以下錯誤本地的TimesTen庫:

[ERROR] 
java.sql.SQLException: Problems with loading native library/missing methods: Native Library /opt/timesten/TimesTen/tt1122/lib/libttJdbcCS.dylib already loaded in another classloader 

我如何在Maven中克服這些問題,特別是?

僅供參考,我的pom.xml如下所示:

<?xml version="1.0"?> 
<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> 

    <parent> 
     <groupId>com.xxx.xxx</groupId> 
     <artifactId>xxx</artifactId> 
     <version>x.x.x.x-SNAPSHOT</version> 
    </parent> 

    <groupId>x.x.x.x</groupId> 
    <artifactId>db-reset</artifactId> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>com.dbdeploy</groupId> 
       <artifactId>maven-dbdeploy-plugin</artifactId> 
       <version>3.0M3</version> 

       <configuration> 
        <scriptdirectory>src/sql/dbdeploy-migrations</scriptdirectory> 
        <driver>${timesten.jdbc.driver.class}</driver> 
        <url>${timesten.jdbc.url}</url> 
        <userid>${timesten.user}</userid> 
        <password>${timesten.password}</password> 
        <dbms>timesten</dbms> 
        <delimiter>;</delimiter> 
        <delimiterType>row</delimiterType> 
       </configuration> 

       <dependencies> 
        <dependency> 
         <groupId>com.timesten</groupId> 
         <artifactId>timesten</artifactId> 
         <version>11.2.2.7.8</version> 
         <scope>system</scope> 
         <systemPath>${timesten.jdbc.library.path}</systemPath> 
        </dependency> 
       </dependencies> 

       <executions> 
        <execution> 
         <phase>pre-integration-test</phase> 
         <goals> 
          <goal>update</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>sql-maven-plugin</artifactId> 
       <configuration> 
        <driver>${timesten.jdbc.driver.class}</driver> 
        <url>${timesten.jdbc.url}</url> 
        <username>${timesten.user}</username> 
        <password>${timesten.password}</password> 
       </configuration> 
       <dependencies> 
        <dependency> 
         <groupId>com.timesten</groupId> 
         <artifactId>timesten</artifactId> 
         <version>11.2.2.7.8</version> 
         <scope>system</scope> 
         <systemPath>${timesten.jdbc.library.path}</systemPath> 
        </dependency> 
       </dependencies> 
       <executions> 
        <execution> 
         <id>drop-db</id> 
         <phase>clean</phase> 
         <goals> 
          <goal>execute</goal> 
         </goals> 
         <configuration> 
          <onError>continue</onError> 
          <srcFiles> 
           <srcFile>src/sql/base/drop.sql</srcFile> 
          </srcFiles> 
         </configuration> 
        </execution> 
        <execution> 
         <id>create-clean-db</id> 
         <phase>clean</phase> 
         <goals> 
          <goal>execute</goal> 
         </goals> 
         <configuration> 
          <srcFiles> 
           <srcFile>src/sql/base/create.sql</srcFile> 
          </srcFiles> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

回答

0

如果這仍是有趣:你可以通過創建一個小的Maven的插件與魔,什麼也不做,但解決的Class.forName這個()插件類。創建一個META-INF/maven/extensions.xml文件,將該驅動程序的包作爲擴展名導出。很早(例如在初始化過程中)運行該插件和specifiy

<extensions>true</extensions> 

實際上,延伸創建通過一次加載驅動程序類(和一次加載本地庫)的所有插件共享的類加載器。

相關問題