【发布时间】:2015-05-10 13:55:29
【问题描述】:
使用maven,我正在构建一个必须动态加载驱动程序的应用程序。使用以下代码,它仅在 driver.so 位于 inside 生成的 JAR 文件时才有效。我该怎么做才能在路径./natives/driver.so 内的JAR 的外部 找到该文件。
package com.myproject;
public class Starter {
public static void main(String[] args) {
File classpathRoot = new File(Starter.class.getClassLoader().getResource("driver.so").getPath());
System.out.println(classpathRoot);
}
}
驱动程序位于inside时的输出JAR是:
jar:file:/home/ted/java/myproject/target/myproject-0.1-SNAPSHOT.jar!/libgdx64.so
定位外部 JAR(在target 和target/natives 目录中)时的输出是:
null
我通过以下方式启动应用程序:
cd /home/ted/java/myproject/target/
java -Djava.library.path=./natives -cp myproject-0.1-SNAPSHOT.jar com.myproject.Starter
我能做什么?
【问题讨论】:
标签: java maven jar shared-libraries