Native Library已经加载到另一个Maven插件的类加载器中

时间:2013-07-05 08:09:05

标签: java sqlite jvm classloader native

我想使用Xerial JDBC driver为SQLite运行两个第三方Maven插件。插件配置大致如下所示:

<plugins>
    <!-- reset database with the SQL Maven plugin -->
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sql-maven-plugin</artifactId>
        <executions>...</executions>
        <dependencies>
            <dependency>
                <groupId>org.xerial</groupId>
                <artifactId>sqlite-jdbc</artifactId>

    [...]

    <!-- generate source code with the jOOQ Maven plugin -->
    <plugin>
        <groupId>org.jooq</groupId>
        <artifactId>jooq-codegen-maven</artifactId>
        <executions>...</executions>
        <dependencies>
            <dependency>
                <groupId>org.xerial</groupId>
                <artifactId>sqlite-jdbc</artifactId>

    [...]

现在,这个SQLite JDBC驱动程序在内部加载了一个本机库,导致第二个插件执行时出现以下错误:

java.lang.UnsatisfiedLinkError: Native Library 
C:\Users\Lukas\AppData\Local\Temp\sqlite-3.7.151-amd64-sqlitejdbc.dll
already loaded in another classloader

解决方法是注释掉其中一个插件。

有没有一种正确的方法来避免这个问题而不对其运行的系统做出任何假设?我想用上面的内容创建自包含测试,它应该在任何系统上运行,即将内容放入系统库路径不是解决方案。这可以用Maven解决吗?或者是否需要修复上述任何插件或(更有可能)JDBC驱动程序?

0 个答案:

没有答案