473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to locate external configuration file

I'm new to Java programming. I'm developing a Servlet for tomcat which needs
an external configuration file. With external I mean a file (in XML format)
which
is customizable and not contained in my package. I don't want to hardcode
any
path and I would like to be independent of the application server (tomcat,
websphere,...).
Until now, I put the file in my package and open it using
obj.getClass.getResourceAsStream
but when I put my whole package in a .jar file, it prevents that the file is
customizable
(or the .jar file would have to be unpacked on each installation).
Putting any path in the web.xml has the same problem.
The article @ javaworld
(http://www.javaworld.com/javaworld/j...cooltools.html)
didn't help because the JDBC connection string actually belongs into the
configuration file.
Also defining a system property when starting tomcat (-Dparam=value) is not
a very good
option as it complicates work for the IT manager (already complicate with
JAAS,
required changes in tomcat's catalina.policy,...).
Someone got any experience how to easily configure a servlet, keep the
configuration
customizable (the configuration itself as well as the location of the
configuration file) and
how to locate the configuration file in a file-system- and
application-server-independent way?

Many thanks
Alex
Jul 17 '05 #1
2 8647
Alex,

Every Appserver has some sort of common area where all applications
installed on the app server can look for classes common to all applications.
In Tomcat it's shared/classes. In WebSphere it's
WebSphere/Appserver/lib/ext, or configurable as a classpath variable in the
admin console. It sounds like putting your XML file in one of these common
areas would be the least amount of work for an installer.

Merrill

"Alexander Kienzle" <no****@nomail.com> wrote in message
news:cd**********@atlas.ip-plus.net...
I'm new to Java programming. I'm developing a Servlet for tomcat which needs an external configuration file. With external I mean a file (in XML format) which
is customizable and not contained in my package. I don't want to hardcode
any
path and I would like to be independent of the application server (tomcat,
websphere,...).
Until now, I put the file in my package and open it using
obj.getClass.getResourceAsStream
but when I put my whole package in a .jar file, it prevents that the file is customizable
(or the .jar file would have to be unpacked on each installation).
Putting any path in the web.xml has the same problem.
The article @ javaworld
(http://www.javaworld.com/javaworld/j...cooltools.html)
didn't help because the JDBC connection string actually belongs into the
configuration file.
Also defining a system property when starting tomcat (-Dparam=value) is not a very good
option as it complicates work for the IT manager (already complicate with
JAAS,
required changes in tomcat's catalina.policy,...).
Someone got any experience how to easily configure a servlet, keep the
configuration
customizable (the configuration itself as well as the location of the
configuration file) and
how to locate the configuration file in a file-system- and
application-server-independent way?

Many thanks
Alex

Jul 17 '05 #2
Hi Merril

Thanks for the answer, but how do I find that directory?
I assume I cannot use getResourceAsStream in those cases but I'm not
sure because the ClassLoader's getResourceAsStream method will
look in many places (the order which directories are searched is not
described in my Java docs!).

Using System.GetProperties("catalina.home") + "shared/..." would not
work if the application server is websphere (and vice versa).
Could I just try 'catalina.home' and if it fails, assume that the
application server is websphere and use the websphere's
system property to get to the path or is there a more generic way
to find the actual application server?

I also have another problem, that is, when I have multiple versions of
my package (using different context-path). They would most probably
require different configuration files. Is it possible to put the
configuration
file in the same directory as the .jar file? Will getResourceAsStream
work then? If not, how can I find out in which directory the .jar file is
(maybe ServletContext.getRealPath("/"))?

Thanks in advance

Alex

"Merrill" <mh*********@socal.rr.com> wrote in message
news:gZ*******************@twister.socal.rr.com...
Alex,

Every Appserver has some sort of common area where all applications
installed on the app server can look for classes common to all applications. In Tomcat it's shared/classes. In WebSphere it's
WebSphere/Appserver/lib/ext, or configurable as a classpath variable in the admin console. It sounds like putting your XML file in one of these common areas would be the least amount of work for an installer.

Merrill

"Alexander Kienzle" <no****@nomail.com> wrote in message
news:cd**********@atlas.ip-plus.net...
I'm new to Java programming. I'm developing a Servlet for tomcat which needs
an external configuration file. With external I mean a file (in XML

format)
which
is customizable and not contained in my package. I don't want to hardcode any
path and I would like to be independent of the application server (tomcat, websphere,...).
Until now, I put the file in my package and open it using
obj.getClass.getResourceAsStream
but when I put my whole package in a .jar file, it prevents that the file is
customizable
(or the .jar file would have to be unpacked on each installation).
Putting any path in the web.xml has the same problem.
The article @ javaworld
(http://www.javaworld.com/javaworld/j...cooltools.html)
didn't help because the JDBC connection string actually belongs into the
configuration file.
Also defining a system property when starting tomcat (-Dparam=value) is

not
a very good
option as it complicates work for the IT manager (already complicate

with JAAS,
required changes in tomcat's catalina.policy,...).
Someone got any experience how to easily configure a servlet, keep the
configuration
customizable (the configuration itself as well as the location of the
configuration file) and
how to locate the configuration file in a file-system- and
application-server-independent way?

Many thanks
Alex


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: shawnk | last post by:
I want to use the Hosts file to locate schema for validation. The Hosts file (C:\Windows\System32\etc) will locate xsd schema files on a LAN server for development purposes. This gives me a...
4
by: Andrew Poulos | last post by:
I've got a page, that's in a frame in a frameset, that calls multiple external js files. When I get a message that tells me that a problem occurred at line, say, 185 is there some way to track down...
0
by: sp1dEr | last post by:
Hi all, I have an asp.net application (framework 1.1 sp1) on windows server 2003. When the document root is locate in local that's all ok... but if the document root is locate on locate on...
3
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard...
0
by: Tom P | last post by:
I'm using System.Configuration in .NET 2.0 to load in values from an externally specified config file and deserialize them into a C# class. During deserialization, I'm getting an exception thrown...
2
by: ras26 | last post by:
I have a WebSite "App1" which has an external assembly "Lib1". Inside this external assembly we have developed some classes that derive from "System.Web.UI.Page". One of these pages is called...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
3
by: bowser | last post by:
Hello, I'm using g++ over eclipse in a mac os x. I'm new to all these technologies. I created a dylib, and to test it I made another project that links to it, but the compiler tells me that it...
0
by: Andrea Anastasescu | last post by:
Hi everybody, Inside the web.config of my application I have some custom sections. I have my own handlers for these sections, and their content is in external files. My problem is that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.