1

I use Gradle to manage a Java project. In C# I'm able to set a number of files as embedded resource and access them at runtime.

https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_project_layout says src/main/resources is for Production resources, such as XML and properties files. Therefore I put my resource files there.

enter image description here

Now how do I access and copy out these files in my Java code?

Many posts talk about classpath, user.dir, or sort of things. I don't know what they are, but I specifically only deal with these files in the resources folder.

I tried https://stackoverflow.com/a/3923182/746461, it lists thousands of files, which looks like too powerful, and I don't know what is the best way to limit the scope.

Besides, I also need my program to copy out these exact files to, say C:\tmp, and keep the folder structure. How would I do that?

Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
  • Does this answer your question? [How to list the files inside a JAR file?](https://stackoverflow.com/questions/1429172/how-to-list-the-files-inside-a-jar-file) – Abhijit Sarkar Sep 23 '21 at 04:16
  • @AbhijitSarkar I'm not talking about jar. As Code-Apprentice answered, Gradle does not include these files in jar. I'm fine with puting them to jar, just advise me how to do it. I merely need to copy out a bunch of embedded things. I don't care how they are embedded, in jar or in a separate folder. – Gqqnbig Sep 23 '21 at 04:22

1 Answers1

0

From what I can tell you can read them directly from resources/.... The gradle doc that you linked also explains that the resources directory is copied to $buildDir/resources/$name when the project is built. So the compiled project will be able to access the same relative path.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268