This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes WAR files in JBOSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Reply locked New topic

WAR files in JBOSS

igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
Hello, I have a fairly serious problem. I have a web application deployed as a WAR file, service.war. Now inside this WAR file, specifically the WEB-INF folder, I have a portable HSQL database. Previously I didn't know how JBOSS works, I didn't know that it extracts the WAR file to the tmp folder. What this meant was that each time I restart JBOSS all the data in my HSQL database and my XML files appear to be wiped out or reset. My question basically is, is there a way of specifying that certain files in my WAR file are not to be deleted or that each time the WAR file is redeployed or reloaded, those files will remain in the state they were in the tmp directory. Thanks.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Would it make sense to "externalize" the HSQL data file instead of keeping it located inside WEB-INF (or wherever you put it inside the .war)?

For example, instead of reading the database from "/WEB-INF/hsql.db", reading it from "/tmp/myapp/hsql.db".

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
norman richards
Ranch Hand

Joined: Jul 21, 2003
Posts: 367
Lasse is right, you should externalize this. Writing data into the WAR file/directory is a bad idea. JBoss provides the data directory (server/default/data, for example) for you to place application data that you want to survive a server reset. In fact, that's exactly where JBoss puts the hypersonic database that it provides to you.

And that begs the question, why not simply use the HSQL JBoss provides? Or better yet, why not simply use a standard datasource and not overcomplicate your application with database-specific code? One of the things that makes application servers so appealing is that you can externalize services your application requires and make your life much simpler.
igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
Hi, thanks for your replies. However I am really new to JBOSS and probably can't act on everything you have suggested. My question now is, from a JSP page, how can I get to the JBOSS data folder? In my JSP page, to get to Card.xml in WEB-INF/templates I use

String cardPath = getServletContext().getRealPath("WEB-INF/templates/Card.xml");

How can I do the same to get Card.xml in the server/default/data directory. Thanks.
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 292

You can get the data directory by doing something like:

Adrian Precub

Joined: Jan 31, 2008
Posts: 11

Can you please tell me how can i acces a picture stored in jboss server/default/data directory in my jsp?

Thank you.

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 9962

Adrian Precub wrote:Hello,

Can you please tell me how can i acces a picture stored in jboss server/default/data directory in my jsp?

Thank you.

Let's continue the discussion on your question here

[My Blog] [JavaRanch Journal]
I agree. Here's the link:
subject: WAR files in JBOSS
Similar Threads
Extracting jar file contents to JBOSS tmp directory
how to find the location of the dynamic tmp folder created by JBOSS
MBeans waiting for other MBeans
Jboss deleted tmp folder each time?
Folder Deployment