简体   繁体   中英

Access resources (with input data and configuration) from within jar-file

I have a maven project which I develop using intellij IDEA. I have specified a resource directory in intellij which contains some configuration files and data files. 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. Is there a flag to java to point out the resources directory?

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. However, it seems as I cannot use -classpath to specify where the classLoader should look, as there is no difference in behaviour.

I can of course open a normal text file, but I would rather have it work from the classLocader machinery.

If you are using Maven stucture you shoud have 2 directories - java/main/src with sources and java/main/resources with app resources. Both are copied into JAR

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM