473,796 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ge tResourceAsStre am
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 8684
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.ge tResourceAsStre am
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 getResourceAsSt ream in those cases but I'm not
sure because the ClassLoader's getResourceAsSt ream method will
look in many places (the order which directories are searched is not
described in my Java docs!).

Using System.GetPrope rties("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 getResourceAsSt ream
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*********@so cal.rr.com> wrote in message
news:gZ******** ***********@twi ster.socal.rr.c om...
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.ge tResourceAsStre am
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
1333
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 alias mechanism for XML namespace redirection. If the host file on a client machine has the entry; 192.168.1.12 XML-srv
4
1291
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 the actual line of code referred to? At the moment I have no idea where exactly IE had the problem. Something like MZ's js console would be nice. Andrew Poulos
0
1279
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 network share, application display error message: Server Error in '/MYAPP' Application. --------------------------------------------------------------------------------
3
5773
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 drive onto a USB External Hard Drive. I have to assume I also copied the data. I
0
3029
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 by .NET It's having a problem with the <connections> element seen below. I've tried different things, but still I can't get the deserialize to succeed. Here's the problem in detail below. Can anybody tell me what I'm doing wrong? Shouldn't...
2
2084
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 "WebNotification". In the WebSite "App1" we create an instance of "WebNotification", but when this class tries to access some Session variables it generates the following error: Session state can only be used when enableSessionState is set to...
2
5334
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: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
3
4942
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 can't locate it. In my last build I used absolute path to be sure of the location, but it still delivers an error. The output is: **** Build of configuration Debug for project gnawa_tester ****
0
1339
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 ConfigurationManager do not detects that these external files are changed. In case that I "touch" the web.config file, just save it or something, the content of the files are re-read. Is there any possibility to make ConfigurationManager detect that these...
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.