-
1. Re: Class.getResource returns odd path when running Arquillian and using ShrinkWrap
aslak Aug 6, 2013 10:17 AM (in response to jrhite_boss)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
-
2. Re: Class.getResource returns odd path when running Arquillian and using ShrinkWrap
jrhite_boss Aug 6, 2013 10:38 AM (in response to aslak)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:
vfs:/content/test.war/WEB-INF/lib/92aff46b-5c2a-41ac-b34c-62066f4c8475.jar/datasets/testdata.json
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.
-
3. Re: Class.getResource returns odd path when running Arquillian and using ShrinkWrap
aslak Aug 6, 2013 4:40 PM (in response to jrhite_boss)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
http://docs.oracle.com/javase/7/docs/api/java/net/URL.html#getFile()
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()))
-
4. Re: Class.getResource returns odd path when running Arquillian and using ShrinkWrap
jrhite_boss Aug 6, 2013 8:27 PM (in response to aslak)Ah, right, totally missed that fact. I made the changes you suggested and it works perfectly.
Thanks!