2

Source is a Java Maven project.

Java resources directory contains subdirectories that contain configuration files. Config files can be added and removed as a maintenance process. Names of files not suppose to be known.

How I can get a list of all files in a mentioned project "resources" directory?

There is a solution using Spring framework class PathMatchingResourcePatternResolver, however this class requires Apache Commons Logging and when dependency added the project is getting set to java 1.7 source from 1.8 that breaks existing code compatibility.

Does java have a class that can list files of a mentioned folder, or java was never need it?

Update: Was able to resolve the issue with this solution (else condition //Run with IDE) https://stackoverflow.com/a/20073154/323128

path is a folder name inside "resources" directory.

Community
  • 1
  • 1
Maxim
  • 4,152
  • 8
  • 50
  • 77
  • 2
    @Burkhard Not a duplicate to the referred question. – Maxim Mar 18 '16 at 20:36
  • 2
    Thank you for closing without help ignorant community members! You could help at least with a right link if you took time to read the question. – Maxim Mar 21 '16 at 13:01

1 Answers1

1

You can use the JarFile class to interrogate the contents of JARs programmatically: https://docs.oracle.com/javase/7/docs/api/java/util/jar/JarFile.html.

Some examples: http://www.programcreek.com/java-api-examples/java.util.jar.JarFile

You can also use jar.exe from the JDK itself to interrogate JAR files. This command will show everything under the resources level from the root...

jar tf YourApplication.jar resources

The Guava ClassPath class may also be worth looking at: (https://github.com/google/guava/blob/master/guava/src/com/google/common/reflect/ClassPath.java).

ManoDestra
  • 6,325
  • 6
  • 26
  • 50
  • Jar's resource directory. Thank you for links. – Maxim Mar 18 '16 at 20:49
  • Updated my answer to give an additional way of doing it via jar.exe. – ManoDestra Mar 18 '16 at 20:52
  • Your hints brought me to this answer http://stackoverflow.com/questions/11012819/how-can-i-get-a-resource-folder-from-inside-my-jar-file that resolved my question. Thanks for the help and I take it as an answer. – Maxim Mar 18 '16 at 21:10