Re: How to locate external configuration file

From: Alexander Kienzle (nospam_at_nomail.com)
Date: 07/21/04


Date: Wed, 21 Jul 2004 15:29:27 +0200

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" <mhigginson1@socal.rr.com> wrote in message
news:gZ9Lc.42935$SO5.27485@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" <nospam@nomail.com> wrote in message
> news:cditht$qi7$1@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/jw-04-1999/jw-04-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
> >
> >
>
>



Relevant Pages

  • Re: CUPS Server Error
    ... # This is the CUPS configuration file. ... Server Identity ... determines whether the scheduler will allow new printers ... whether or not to use "short" names for remote printers ...
    (Debian-User)
  • Re: ADAM Synchronizer Beta - question
    ... Sorry to get in the middle of a conversation, I think can help Lee a bit ... The server error indicates you are running w2k AD, ... > Saved configuration file. ... > control, data 0, v893. ...
    (microsoft.public.windows.server.active_directory)
  • Re: convert console app to config file?
    ... client project and your server project. ... Start your server application (console app most ... Sam Santiago ... > If I create the configuration file as you very helpfully morphed for me, ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: W2003 Server SP2 Problems with W32TM
    ... I've tested a W2k3 box time synchronization by setting the server using ... the net time interface was written. ... Send SIGHUP to the daemon, the daemon catches the signal, rereads the configuration file and starts making changes! ... config" command on those platforms that do not support the signal events? ...
    (comp.protocols.time.ntp)
  • Classloader problems: getResouceAsStream() returns null
    ... Hibernate does load its configuration file via getResourceAsStream(). ... file is located in classpath. ...
    (comp.lang.java.programmer)