|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.sandev.basics.util.EnvGrabber
public class EnvGrabber
Legacy utility to return the value of an environment variable. If you
are running on Java 5 or later, then you should probably use
System.getEnv to retrieve what you need. Prior to Java 5,
there was no reasonable way of getting this information via the
standard API, so various people wrote workarounds that made a call
to the environment and then parsed up the results. Since environment
calls were expensive (they forked a new JVM), we wrote this utility
to make this call once and then hold onto the results for reference.
The core of this code was originally nicked from http://www.rgagnon.com/javadetails/java-0150.html. Our thanks to Real Gagnon for posting this and making it available.
| Field Summary | |
|---|---|
protected static java.util.Properties |
envVars
The single reference copy. |
| Constructor Summary | |
|---|---|
EnvGrabber()
|
|
| Method Summary | |
|---|---|
static void |
dumpProperties(java.util.Properties props)
Go through all the property keys and dump out the corresponding values WITHOUT TRUNCATING. |
static void |
envDump()
This method takes its best shot at dumping out a whole bunch of properties to stdout. |
static java.lang.String |
getEnvVar(java.lang.String envVarName)
Given the name of an environment variable, return its value. |
protected static java.util.Properties |
getEnvVars()
Code adapted from www.rgagnon.com |
protected static java.util.Properties |
getEnvVarsFromFile()
Attempt to read the env vars from a local file. |
static java.lang.String |
safeGetEnvVar(java.lang.String envVarName)
Catches any thrown IOException and simply returns null. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static java.util.Properties envVars
| Constructor Detail |
|---|
public EnvGrabber()
| Method Detail |
|---|
protected static java.util.Properties getEnvVars()
throws java.io.IOException
java.io.IOException
protected static java.util.Properties getEnvVarsFromFile()
throws java.io.IOException
So for example, if you see from the log that getEnvVars is failing on startup, then you might login (probably as root) and do something like:
cd /opt/tomcat5
env > SANDEnvVarDump.out
chgrp tomcat SANDEnvVarDump.out
chown tomcat SANDEnvVarDump.out
java.io.IOException
public static java.lang.String getEnvVar(java.lang.String envVarName)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String safeGetEnvVar(java.lang.String envVarName)
public static void envDump()
list method since that truncates the displayed
values (typically right where you wanted to see it).
public static void dumpProperties(java.util.Properties props)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||