2

I am developing a Java EE application for JBoss 6.1.0 which needs to programmatically store image files on disk.

How/where should I store image files on a JBoss server?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 2
    that's like saying "I have a Toyota, where should I go for lunch"? It really depends on what you want/need. – eis Jan 22 '15 at 05:45
  • Sorry about the vagueness. Let me give you some more information. I am developing an e-commerce application using Java EE technologies such as JPA, JSF, Entity Beans, Stateless and SFSB, managed Beans and the Facade Design Pattern. The application sells car parts and I'd like to store the images of these car parts in the application server (in this case JBOSS 6.1.0) My questions are.1. Can I store the images of my product catalogue in the Application Server? If so, where? Thanks. – Lalin Pethiyagoda Jan 22 '15 at 06:11
  • You used the word "JEE" in your question. May I please point you on this? https://java.net/projects/javaee-spec/pages/JEE – BalusC Jan 22 '15 at 08:16
  • Dear Balus C. I thought I HAD used Java EE, not JEE. Sorry but I cannot find any refernce to JEE in my text. But I totally agree with you . It is Java EE, not JEE. Lalin – Lalin Pethiyagoda Jan 22 '15 at 08:56
  • Sorry, if I HAD used JEE but you subsequently corrected it. My apologies. – Lalin Pethiyagoda Jan 22 '15 at 08:57

1 Answers1

2

You can use the /standalone/data folder for this, whose path is available via the jboss.server.data.dir system property.

File dataDir = new File(System.getProperty("jboss.server.data.dir"));
File yourFile = new File(dataDir, "filename.ext");
// ...

You are even allowed to create subfolders in there. Below example creates /standalone/data/images.

File imagesDir = new File(System.getProperty("jboss.server.data.dir"), "images");
imagesDir.mkdir();
File yourImageFile = new File(imagesDir, "image.png");
// ...

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you! as always, you are a life saver Balus C! – Lalin Pethiyagoda Jan 22 '15 at 11:46
  • A quick question, How do I reference this location from inside a JSF file. I want to show an images on the welcome page but I cannot get the image to come up. – Lalin Pethiyagoda Jan 30 '15 at 15:42
  • Use the servlet approach http://stackoverflow.com/questions/4543936/load-images-from-outside-of-webapps-webcontext-deploy-folder-using-hgraphi/ (this link is mentioned in bottom of "How to save uploaded file" link in above answer) – BalusC Jan 30 '15 at 15:44
  • so, I store the images in the data folder in JBOSS. then use a servlet to access it? I am using JBOSS 6.1.0 as my AS I'm sorry BalusC but I am not quite clear as to how I should proceed here. – Lalin Pethiyagoda Jan 30 '15 at 15:57
  • Just substitute `"/path/to/images"` part in the servlet example. Logical, right? – BalusC Jan 30 '15 at 15:59
  • yes it does: so am I right here? pathToImages = "JBOSS6.1.0/server/default/data" – Lalin Pethiyagoda Jan 30 '15 at 16:11
  • No .. The same as in above answer. – BalusC Jan 30 '15 at 16:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69908/discussion-between-lalin-pethiyagoda-and-balusc). – Lalin Pethiyagoda Jan 30 '15 at 16:15