Date Created: Tue 26-Aug-2008

Related Document Categories:

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/



Get Unix environment variables using Java

Often in corporate development situations where a third party vendor is developing applications, the third party developers employ Unix variables in early versions of their products (We do not accept this and ask for them to be removed) and though they should not be using Unix variables in a J2EE application they do so.

I recently had a situation where I had to prove that the J2EE web application could not see the variables. Also often off shore development teams resources come from a windows back ground and are thrust into a Unix project and do not understand Unix profiles and often ask for the server to be rebooted when an application doesn't work saying that the environment variables are not being picked up by the WebSphere J2EE application.

Well for a start I do not restart an AIX LPAR just so an environment variable can proven to exist, so to prove Unix profiles work and that an application has the issue I developed two tools.

1. Simple Java class that displays the Unix variable as passed in on the command line and proves or disproves whether a JVM can see or not see the Unix variable set in the profile of the user that JVM is running under.


import java.lang.System;
import java.util.Map;

public class DumpEnvVars {
public static void main(String args[]) {

for (Map.Entry entry: System.getenv().entrySet()) {
System.out.println(entry.getKey() + " / " +
entry.getValue());
}

}

}

Project Interchange from RSA 7.0

env_app.zip

2. A Simple EAR file that contains a Web Application (WAR) that uses a servlet to output Unix environment variable passed in by query string and shows whether the web container's JVM ie WebSphere can see the Unix environment variables.


Project Interchange from RSA 7.0

EnvironmentWebEAR.ear

env_j2ee_app.zip

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/

Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


  • Linked In
  • Twitter
  • About Me
  • My Blog
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories