5

I have servlet deployed in JBoss. I want to read/write data into a text file based on the client input. Where should this text file be put in the JBoss directory structure?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ashwin
  • 12,691
  • 31
  • 118
  • 190

1 Answers1

10

There the /data directory is for.

enter image description here


Its absolute path is available by the jboss.server.data.dir system property.

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

See also:

Note that you're this way tight-coupling the web application code to a specific server. If you ever want to change servers, keep in mind to change the above code as well to whatever the new server supports (or not).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Is the system property "jboss.server.data.dir" already present in the jboss jre? – Ashwin Feb 27 '12 at 23:51
  • Yes, it's set by JBoss itself, but it's overridable by a manual `-Djboss.server.data.dir` VM argument. – BalusC Feb 27 '12 at 23:55
  • I also have images to be displayed in my jsp pages which are deployed in jboss. I put the images in the .war file outside the WEB-INF directory along with the jsp files. the jsp files are not showing the pictures. Should I put the images in the data directory also? What should I do? – Ashwin Mar 19 '12 at 09:35
  • I don't get you. Should I speciy the abolute path of the images. What I have done referred the image with its name in the jsp page since both the jsp and the images are in the same directory. – Ashwin Mar 19 '12 at 14:36
  • You just didn't give sufficient information to point out the real cause, so I can't give a more detailed answer. If an image don't show up, then its URL is wrong. Simple as that. I can only add the hint that any HTML page resource URLs are resolved relative to the request URL (as you see in browser address bar). So if your JSP happen to be requested through a virtual URL for example, then the image URL should be altered based on that. – BalusC Mar 19 '12 at 14:38
  • Okay I will explain in detail. I have a 'tmp'. Inside it, there are jsp files and some images(to be used as the background in the jsp files-the path is just the name of the image). inside the tmp folder, there is also a 'WEB-INF' folder which contains the web.xml. Now I went to the 'tmp' foldr and made war file of all the contents of the tmp folder- 'hello.war'. Then I put this 'hello.war' in the deploy directory of the jboss. And then went to the url locahost:8080/hello/xyz.jsp. But only the the textual contents of the jsp file is being displayed and the images are not. – Ashwin Mar 20 '12 at 01:23
  • @BalusC Could you tell me please where I can information about this but in JBoss AS 7.1? – John Alexander Betts Oct 09 '13 at 14:32
  • 1
    @JohnB: The same environment variables are available. Only folder structure has changed; it's now all in `/standalone`. See also https://docs.jboss.org/author/display/AS71/Command+line+parameters – BalusC Oct 09 '13 at 14:35
  • Thanks @BalusC I just found too. Always, you are the greatest one – John Alexander Betts Oct 09 '13 at 14:37