Sql 多个Maven插件依赖项-本机库已加载到另一个类加载器中
我正在尝试编写一个maven脚本,该脚本使用sql maven插件删除并重新创建Oracle TimesTen数据库,然后在预集成测试阶段使用dbdeploy应用大量数据库迁移脚本 这两个插件都需要使用本机timesten库,当然不同的类加载器无法加载本机timesten库,从而产生以下错误:Sql 多个Maven插件依赖项-本机库已加载到另一个类加载器中,sql,maven,plugins,classloader,timesten,Sql,Maven,Plugins,Classloader,Timesten,我正在尝试编写一个maven脚本,该脚本使用sql maven插件删除并重新创建Oracle TimesTen数据库,然后在预集成测试阶段使用dbdeploy应用大量数据库迁移脚本 这两个插件都需要使用本机timesten库,当然不同的类加载器无法加载本机timesten库,从而产生以下错误: [ERROR] java.sql.SQLException: Problems with loading native library/missing methods: Native Library /o
[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中如何克服这些问题
为了便于参考,my 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>
4.0.0
com.xxx.xxx
xxx
x、 x.x.x快照
八位字节
分贝复位
com.dbdeploy
maven dbdeploy插件
3.0M3
src/sql/dbdeploy迁移
${timesten.jdbc.driver.class}
${timesten.jdbc.url}
${timesten.user}
${timesten.password}
十倍
;
一行
com.timesten
十倍
11.2.2.7.8
系统
${timesten.jdbc.library.path}
预集成测试
使现代化
org.codehaus.mojo
SQLMaven插件
${timesten.jdbc.driver.class}
${timesten.jdbc.url}
${timesten.user}
${timesten.password}
com.timesten
十倍
11.2.2.7.8
系统
${timesten.jdbc.library.path}
下降分贝
清洁的
处决
持续
src/sql/base/drop.sql
创建干净的数据库
清洁的
处决
src/sql/base/create.sql
如果这仍然很有趣:您可以通过使用Mojo创建一个小型maven插件来解决这个问题,Mojo除了Class.forName()插件类之外什么都不做。创建META-INF/maven/extensions.xml,将驱动程序包导出为扩展。尽早运行此插件(例如在初始化期间)并指定
<extensions>true</extensions>
true
实际上,扩展创建了一个由所有插件共享的类加载器,驱动程序类加载一次(本机库加载一次)