1

I am able to read a particular resource into an InputStream.

InputStream inputStream = MyClass.getResourceAsStream("/resources/test.xml")

But I cannot get a list of all resource files in the resources package for some reason.

I have tried the code from this answer to no avail.

Edit: I am only interested in getting a list of the file names from the resources package.

Edit 2: The code is called from a runtime eclipse instance.

User48591
  • 301
  • 1
  • 2
  • 10
  • 5
    @HemantPatel That won't give you a list of resources – Mark Rotteveel May 18 '18 at 08:12
  • 1
    @HemantPatel - there is no relative path passed – Scary Wombat May 18 '18 at 08:16
  • 1
    Possible duplicate of [Get a list of resources from classpath directory](https://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory) – Jan Ossowski May 18 '18 at 08:16
  • 1
    What exactly is the "resources package" ? Is this a directory ? packaged in a JAR ? Where is it located ? – yunandtidus May 18 '18 at 08:27
  • @yunandtidus It is a package located directly under src. Here is a screenshot. https://i.imgur.com/MSXarMZ.png – User48591 May 18 '18 at 08:35
  • There is no single line solution to your problem, you should take a look at answers in https://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory (pointed out by @JanOssowski) – yunandtidus May 18 '18 at 08:56

1 Answers1

2

Most of the answers to this question presume that the resource is being found as a 'loose' (not in a Jar) file on the local file system. But once deployed, those types of things will likely be inside a Jar and any use of the File class will fail to act as a file (because it's not).

To get a listing from inside a Jar, insert a textual list into the Jar at build time that lists each other resource of interest. At runtime, load the list, then proceed from there.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • I believe that the OP's linked answer does a brute force iteration of `JarEntry` objects if the resource is not a directory – Scary Wombat May 18 '18 at 08:26