質問

I have a Spring webservice which is deployed as a war in Jboss-eap-6.1.

The code needs to read an image at run time. Iam trying to package the image with the war and deploy it in Jboss.

I make sure that the image is put in /WEB-INF/classes directory of the war. I am trying to read the image this way in the code:

final String path = this.getClass().getClassLoader().getResource("jeffmor.jpg").getPath(); 
File noImage = new File(path);

But the code is not able to pick this image up. If I do a System.out.println in the value of path, it comes as

/content/Service.war/WEB-INF/classes/jeffmor.jpg

Iam not sure whERE the '/content' part got added from? Why is the code not able to pack the image packaged in the war and is there any better way for the code to read a file that is packaged in its own war in Jboss eap 6.1.

役に立ちましたか?

解決

Application server can deploy your archive without unpacking them. You should be using so -

java.lang.ClassLoader.getResourceAsStream("jeffmor.jpg");

Addition.

Your call return a URL of object.

See Also

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top