chris brown wrote:
>
> Thanks for your suggestions!
>
> Just to confirm my understanding of your suggestion, I tried out the
> following:
>
> // Start of example class
> import java.io.*;
> import java.util.*;
>
> public class PropTest2
> {
> public static void main (String args[])
> {
> File libDir = null;
> try {
> libDir = new File(
> System.getProperty("java.home") +
> File.separatorChar + "lib");
> }
> catch (SecurityException e) {
> System.out.println("SecurityManager prevents access to system
> properties.");
> return;
> }
>
> File propFile = new File(libDir, args[0]);
> System.out.println("Expecting properties in: "+propFile.getPath());
> Properties p = new Properties();
> try {
> p.load(new FileInputStream(propFile));
> }
> catch (Exception e) {
> System.out.println(e.toString());
> return;
> }
>
> p.list(System.out);
> }
> }
> // End of example class
>
> This works, but I was wondering if there was anyway to access the host
> platform's environment variables, not just those of the JVM (with a few
> vendor-specific properties)? I had a look around the System and Runtime
> classes in java.lang, but didn't see any obvious way of getting at them.
Java doesn't provide direct access to environment variables. But for
a container that is started by a script, you can add -D flags to the
java command invocation to set system properties to environment variable
values:
java -Duser=%USER% ...
on a Windows platform, and get them in the Java code:
String user = System.getProperty("user");
> This might be a bit "cleaner", or simpler for an administrator with little
> knowledge of Java, because -- for a start -- it's not always obvious which
> JVM is used by a web app container (yes, I know it's possible to find out,
> but the whole point of this thread is to simplify deployment).
>
> I had also thought about using the webapp's server's lib dir, as you
> suggested, but wasn't sure of a way to construct server-independent
> pathnames towards the "lib" folder of the server.
There's really no portable way to do this. The container may not even have
a "lib" folder.
> As for your classpath suggestion, do you mean reading the classpath system
> property ("java.class.path"), then looking in each path in the list for the
> specified file?
I assume that what Joseph had in mind was putting your properties file
in the web application's or web container's classpath, and use
Class.getResource()
to read it in your application. This may or may not work. Reasons it may
not work is that how Class.getResource() finds a resource is defined by
the class loader that loaded the class, and there's no guarantee that it
will look for resources in its classpath. A Web container typically uses its
own special class loaders, and may not follow the same conventions as the
standard class loaders that part of the JDK (even though most class loaders
do).
> Other than that... which address do you believe would be most effective for
> whining to Sun...?
For feedback on the servlet specification:
[EMAIL PROTECTED]
For feedback on the JSP specification:
[EMAIL PROTECTED]
> In any case, thanks for your suggestions. Much appreciated!
>
> -Chris
Hans
> ----- Original Message -----
> From: "Joseph Ottinger" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, June 07, 2001 3:09 PM
> Subject: Re: Deploying a web app as a war file then supplying init params
>
> > Simplest way: whine and moan at Sun to put in deployment-level environment
> > variables.
> >
> > Real way: use property files, and put your custom properties in the
> > classpath. (i.e., in the application lib dir, or the application server
> lib
> > dir, or even higher, if you like.)
> >
> >
> > >From: chris brown <[EMAIL PROTECTED]>
> > >Reply-To: A mailing list about Java Server Pages specification and
> > >reference <[EMAIL PROTECTED]>
> > >To: [EMAIL PROTECTED]
> > >Subject: Deploying a web app as a war file then supplying init params
> > >Date: Thu, 7 Jun 2001 10:46:58 +0200
> > >
> > >Hello,
> > >
> > >I'm developing a web app which I plan to deploy on several systems. I'm
> > >trying to avoid hard-coding anything into the app, so for example
> database
> > >connections, log file paths, etc. are specified as init-params on the
> > >appropriate servlets.
> > >
> > >When I deploy this as a "war" file (web archive), I'd like it if the
> > >administrator of the system where it's being deployed can modify the init
> > >params WITHOUT unarchiving / decompressing the archive (especially I need
> > >to
> > >sign or otherwise encrypt the archive). If not, how else can I design an
> > >app so that it's portable and easy to deploy?
> > >
> > >Thanks,
> > >Chris
> > >
> >
> >===========================================================================
> > >To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > >JSP-INTEREST".
> > >For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> > >DIGEST".
> > >Some relevant FAQs on JSP/Servlets can be found at:
> > >
> > > http://java.sun.com/products/jsp/faq.html
> > > http://www.esperanto.org.nz/jsp/jspfaq.html
> > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at http://explorer.msn.com
> >
> >
> ===========================================================================
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> > http://java.sun.com/products/jsp/faq.html
> > http://www.esperanto.org.nz/jsp/jspfaq.html
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets