aspose file tools*
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
JavaRanch » Java Forums » Products » JBoss/WildFly
Reply locked New topic
Author

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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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
Author
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: 293

You can get the data directory by doing something like:

Adrian Precub
Greenhorn

Joined: Jan 31, 2008
Posts: 11
Hello,

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

Thank you.


SCJP 1.5 SCWCD 5
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10264
    
168

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 http://www.coderanch.com/t/488645/JBoss/externalize-resources-from-webapp


[My Blog] [JavaRanch Journal]
 
Consider Paul's rocket mass heater.
 
subject: WAR files in JBOSS