[英]Access resources (with input data and configuration) from within jar-file
I have a maven project which I develop using intellij IDEA. 我有一个使用intellij IDEA开发的Maven项目。 I have specified a resource directory in intellij which contains some configuration files and data files.
我在intellij中指定了一个资源目录,其中包含一些配置文件和数据文件。 When I run the program in intellij, there is no issue, but I would like to access these files when I run the jar-file from command line also, and I do not know how to specify for maven that a directory is a resources directory without it being copied into the jar-file, which I do not want.
当我在intellij中运行程序时,没有问题,但是当我也从命令行运行jar文件时,我想访问这些文件,而且我不知道如何为maven指定目录是资源目录而不将其复制到我不想要的jar文件中。 Is there a flag to
java
to point out the resources directory? 是否有
java
标记java
资源目录?
Edit: To be clear, I have my jar file and I want to access a resource directory located outside my jar file using the classLoader. 编辑:明确地说,我有我的jar文件,我想使用classLoader访问位于我的jar文件外部的资源目录。 However, it seems as I cannot use
-classpath
to specify where the classLoader should look, as there is no difference in behaviour. 但是,似乎我不能使用
-classpath
来指定classLoader的外观,因为行为没有区别。
I can of course open a normal text file, but I would rather have it work from the classLocader machinery. 我当然可以打开一个普通的文本文件,但是我希望它可以在classLocader机制中运行。
If you are using Maven stucture you shoud have 2 directories - java/main/src
with sources and java/main/resources
with app resources. 如果您使用的是Maven结构,则应该有2个目录-带源的
java/main/src
和带应用程序资源的java/main/resources
resources。 Both are copied into JAR 两者都复制到JAR中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.