I have a project structure where the resources folder is at the same level as src. The resources folder has got a subfolder config, which has a configuration file conffile.ttl. I have included the resources in the classpath while running the program from eclipse.
我有一个项目结构,其中资源文件夹与src处于同一级别。 resources文件夹有一个子文件夹配置,它有一个配置文件conffile.ttl。我在从eclipse运行程序时将资源包含在类路径中。
While reading the conffile.ttl file from my main class, I use
从我的主类中读取conffile.ttl文件时,我使用了
URL url =TestPropertyFilePath.class.getClassLoader().getSystemResource("conf/conffile.ttl");
System.out.println(url.getPath());
which works fine. However when I bundle this in a jar and try to run the jar using
哪个工作正常。然而,当我把它捆绑在一个罐子里并尝试运行jar时
java -jar testprop.jar TestPropertyFilePath
Java cannot find the conffile.ttl file. I would like advice on how to access the conffile.ttl from within the jar.
Java找不到conffile.ttl文件。我想建议如何从jar中访问conffile.ttl。
1 个解决方案
#1
0
Try This:
TestPropertyFilePath.class.getClassLoader().getSystemResource("conf.conffile");
#1
0
Try This:
TestPropertyFilePath.class.getClassLoader().getSystemResource("conf.conffile");