0

I have a Maven project with some .bpmn files in /src/main/resources/bpmn which I am struggling to load into my Java app. This loading process occurs inside a .jar file which is loaded at runtime by a .war web app.

I have tried:

MyClass.class.getClassLoader().getResourceAsStream("/bpmn"); and
MyClass.class.getResourceAsStream("/bpmn");

which returns an input stream which I've constructed a BufferedReader from:

new BufferedReader(new InputStreamReader(inputStream));

But when I go to read the lines, there's nothing. I was expecting that when I read the lines it would output the names of the files in that folder.

If I try

MyClass.class.getClassLoader().getResource("/bpmn");

and print the URL, it returns the correct path, but when I try and construct a file object, I get a java.lang.IllegalArgumentException: URI is not hierarchical.

Would someone be able to point me in the right direction?

Thank you

Matthew Satti
  • 103
  • 2
  • 13
  • 1
    You can't read folders as resources. Only files. – JB Nizet May 02 '19 at 06:43
  • Possible duplicate of [Why is my URI not hierarchical?](https://stackoverflow.com/questions/18055189/why-is-my-uri-not-hierarchical) – Mebin Joe May 02 '19 at 06:43
  • try reading https://stackoverflow.com/questions/18055189/why-is-my-uri-not-hierarchical – Adi Ohana May 02 '19 at 06:43
  • You need to provide more details about your environment. Is the Myclass a member of your jar file. what is your .war file(package) structure? Do you check the file existed in a jar you take? – tommybee May 02 '19 at 09:02
  • @JBNizet I wasn't aware of that, thank you. I guess I'll find a different approach. – Matthew Satti May 02 '19 at 09:44

0 Answers0