Question

I am actually loading OWL files in my java web app with the following code:

InputStream is = Dummy.class.getResourceAsStream("content.owl");

I created Dummy.class in the same package as content.owl is to get access to this file.

Is there a (refactor-safe) way to load content.owl directly without the need of a dummy class?

Was it helpful?

Solution

I think you should be able to get that resource from any class by giving relative path of it according to location of output folder where your compiled files are put.

For example initially the resource file in proj/src/a/b/content.owl package and the class I access this resource is in package proj/src/a/b/c/d/MyClass.java. After building the project my executables go under bin folder and the class I access the resource goes to proj/bin/a/b/c/d/MyClass.class directory and resource goes into proj/bin/a/b/content.owl.

And as bin folder is specified as the output folder in classpath of my project, I can access to resource with the code:

InputStream is = MyClass.class.getResourceAsStream("/a/b/content.owl");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top