• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Avneet Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use a properties file to supply specific information.
 
Avneet Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20983
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 42
1
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic