我有一个程序使用的库。该库在资源文件夹中加载一个特殊的目录。如何访问Java中的调用程序的资源目录
在库我有方法
public class DataRegistry{
public static File getSpecialDirectory(){
String resourceName = Thread.currentThread().getContextClassLoader().getResource("data").getFile().replace("%20", " ");
File file = new File(resourceName);
return file;
}
}
在我的程序
我的主要方法
public static void main(String args[]){
System.out.println(Data.getSpecialDirectory());
}
当我的数据程序内执行getSpecialDirectory()在JUnit测试,该资源被提取并且一切都很好。
当我在数据程序(导入jar)之外的主要方法中执行getSpecialDirectory()时,我得到jars数据目录,而不是执行线程的程序所期望的目录。
我觉得得到父类加载器将解决这个问题......我相信我可能在我的理解这里有一个基本问题。
为清楚:https://gist.github.com/AnthonyClink/11275442
(用法) 行此文件的31: https://gist.github.com/AnthonyClink/11275661
我的劲歌可能有一些做
(库) 行此文件的15它,所以分享它们可能很重要:\
(Library) https://github.com/Clinkworks/Neptical/blob/master/pom.xml
(用法) https://github.com/Clinkworks/Neptical-Maven-Plugin/blob/master/pom.xml
什么是你想acheive?获取相对于DataMojo类的文件夹的路径? – tgkprog