我需要读取Manifest传递我的课程的文件,但是当我使用时:
getClass().getClassLoader().getResources(...)
Run Code Online (Sandbox Code Playgroud)
我MANIFEST从第一次.jar加载到Java Runtime.
我的应用程序将从小程序或webstart运行,
因此.jar我猜我无法访问自己的文件.
我实际上想要读取启动Felix OSGi 的Export-package属性.jar,所以我可以将这些包暴露给Felix.有任何想法吗?
我正在尝试从运行Runnable JAR文件获取该位置.我试过了
try {
String path = new java.io.File(".").getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但那回归:
C:\Users\Kevin\Desktop/server/Server
Run Code Online (Sandbox Code Playgroud)
而JAR文件位于
C:\Users\Kevin\Desktop
Run Code Online (Sandbox Code Playgroud)
我也尝试过
return new file(Server.class.getProtectionDomain().getCodeSource().getLocation().getPath());
Run Code Online (Sandbox Code Playgroud)
但那回归:
C:\Users\Kevin\Desktop\server.jar/server/Server
Run Code Online (Sandbox Code Playgroud)
所以我基本上希望JAR文件的路径没有文件名而不是ClassPath.
这样做的任何方式?