相关疑难解决方法(0)

加载jar中包含的资源

在我的应用程序中,我以这种方式加载资源:

WinProcessor.class.getResource("repository").toString();
Run Code Online (Sandbox Code Playgroud)

这给了我:

file:/root/app/repository   (and I replace "file:" with empty string)
Run Code Online (Sandbox Code Playgroud)

当我从IDE运行我的应用程序时,这工作正常,但是当我运行我的应用程序的jar时:

java -jar app.jar
Run Code Online (Sandbox Code Playgroud)

路径变成:

jar:/root/app.jar!/repository
Run Code Online (Sandbox Code Playgroud)

有什么方法可以解决这个问题吗?

我将使用"repository"目录名称来创建:

ConfigurationContext ctx = (ConfigurationContext) ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryString, null);
Run Code Online (Sandbox Code Playgroud)

以同样的方式,我将获得一个文件名(而不是一个目录),我将以这种方式使用它:

System.setProperty("javax.net.ssl.trustStore", fileNameString)
Run Code Online (Sandbox Code Playgroud)

java resources jar

21
推荐指数
3
解决办法
6万
查看次数

标签 统计

jar ×1

java ×1

resources ×1