Nothing wrong with that URL. You got a URL back from getResource which indicate that it actually does exist.
How are you trying to read it?
url.openStream() should work just fine
URL url = testClass.getResource("/datasets/testdata.json");
File testDataFile = new File(url.getFile());
BufferedReader reader = new BufferedReader(new FileReader(testDataFile));
The last line throws a FileNotFoundException.
I'm not sure how to actually debug the contents of the test.war file created by ShrinkWrap. I print its contents and it looks good. But the URL that testClass.getResource(...) returns is:
But the testdata file actually (I believe) lives in: vfs:/content/test.war/WEB-INF/datasets/testdata.json (according to what I see when I print the contents of the war file.
url.getFile() is not usable as a File object unless you happen to be in the same folder structure. It returns the 'file' portion of the URL. e.g. http://localhost:80/test/test.a getFile == /test/test.a
You should follow the URL api and not try to recreate some external resource based on portions of the info the URl describe.
The correct way would be to use openStream to read the content.
new BufferedReader(new InputStreamReader(url.openStream()))
Ah, right, totally missed that fact. I made the changes you suggested and it works perfectly.