wood burning stoves*
The moose likes Servlets and the fly likes How can webapplication read files from local file system based on a environment variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can webapplication read files from local file system based on a environment variable" Watch "How can webapplication read files from local file system based on a environment variable" New topic
Author

How can webapplication read files from local file system based on a environment variable

Avneet Singh
Ranch Hand

Joined: Apr 25, 2006
Posts: 51
Hi All,

The requirement I have is that my web application should read certain data files(xmls) from the filesystem placed by the user and perform the required execution. The webapp can run on all major application servers(jboss/weblogic/websphere ......) and platforms like windows/linux/aix/solaris

The file system where the users choose to place the file is not known and cannot be hard coded in the app due to difference in file structures. Is there a way through which i can access an environment variable in my app, app server independent, to read the files?

Basically I cannot ask users to have a predefined directory or prefer not to, but then through a variable let my app know that the users will place the file at a certain directory.

Any other suggestions would be welcomed.

Thanks.





Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

You should use a properties file to supply specific information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Avneet Singh
Ranch Hand

Joined: Apr 25, 2006
Posts: 51
Thanks, but using a property file would again mean I am assuming the property file to be loaded at a specific location or ask users to repackage the app with the modified property file. I would like to refrain from enforcing a directory structure or repackaging of the ear at user end.

Is it not possible to ask customer to create a specific environment variable which can be accessed from the app running in the jvm? or some other dynamic way to find that path. Another aspect is that this application would be an extension to a enterprise level app deployed which could have it's home directory different at different client locations. I could use the home directory as a possible source but again I need to find out what that directory would be at each location.

This app cannot be made part of the parent enterprise application since its just an extension which customer may or may not choose to have.

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You could certainly ask them to create an environment variable, but remember that the environment variable belongs to the process, i.e. the application server, and not to an individual web application. So for example you would be requiring them to configure their Websphere instance to specify the value of that environment variable.

I leave it up to you to decide whether that is a suitable approach for your customers.
Avneet Singh
Ranch Hand

Joined: Apr 25, 2006
Posts: 51
Thanks , I will look into this, appreciate the help and suggestions.
But if I ask what would be the recommended way will it be the property file?
Also if we go the route of environment variable is there an issues related to app servers I mean WebSphere behaves differently then Jboss or Weblogic?

Thanks
Esteban Herrera
author
Greenhorn

Joined: Dec 25, 2004
Posts: 21

I agree with what Paul said. Environment, session or application variables can be a headache. It can be done this way, maybe configuring the variable in the startup script of the server, but you will need to restart the server if the value changes or modified it with System.setProperty(), but the variable will belong to the process and if for some reasons permissions are denied, then a SecurityException will be thrown.

Why not put the value of the directory in a database? Lilke in a parameter's table. It could have the user identifier to accomodate each user (or group of user) environment.

Another related approach would be to combine the concepts of a database and the properties file. Instead of placing the key/value pairs in a file, put them in a table. Here is a basic example of how can this be accomplish with Spring http://www.codeproject.com/Articles/28893/Loading-Application-Properties-from-a-Database.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How can webapplication read files from local file system based on a environment variable
 
Similar Threads
Servlets and File I/O
properties file in websphere
Classpath error
get directory name from the local file system
Creating a JAR file