Search code examples
javaservletsjbossseam

ServletContext.getRealPath("pictures") returns tmp dir?? JBoss


I made an app with seamgen (also with gui) and i created a folder "pictures" in the root of the application for storing profile images .

When i evaluate ServletContext.getRealPath("pictures") it returns a temporary dir.

D:\Dizertatie\Java\jboss-5.1.0.GA\server\default\tmp\5c4o02s-hw5k2v-gj5pc3oq-1-gj632njx-al\RaceCatalog.war\pictures\1295555156562.jpg

I tried also with the generated img folder and it is still the same thing.

How do I get the relative path

PS. I want to use


Solution

  • As you mentioned in a comment of yours - you need this in order to render images. It is wrong to use this method for that purpose.

    <h:graphicsImage> uses relative path to the root of the application context by default. No extra steps needed.

    As for the behaviour of JBoss in extracting the war file - it seems odd, but it does not violate the specification. It is free to extract unexploded war files wherever it likes.

    Update: If this is about an exploded war (by you), then feel free to fire a bug. But it doesn't matter that much - you shouldn't store pictures in the webapp. Configure an external location and save them there. Otherwise you risk to loose your pictures on redeploy.