PRB: Environment Variables Are Lost When Running from VJ6 IDE (215413)



The information in this article applies to:

  • Microsoft Visual J++ 6.0

This article was previously published under Q215413

SYMPTOMS

When you run a Java application within the Visual J++ 6.0 integrated development environment (IDE), none of the environment variables are set. However, when you run the application from the command line using jview or wjview, variables are set as expected. Note that this also includes the CLASSPATH environment variable.

CAUSE

When you run an application within the Visual J++ 6.0 IDE, the application's environment is not inherited from the parent process and variables are empty. However, when you run it outside the Visual J++ 6.0 IDE (from the command line or otherwise), the application's environment is inherited from the parent process and environment variables have the values of the parent.

RESOLUTION

You need to programmatically set environment variables when you run the application within the Visual J++ 6.0 IDE. To work around this problem, you can start the application outside the Visual J++ 6.0 IDE (using jview) and attach to the process for debugging with access to the environment variables (please see the comments in the sample code below).

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

Compile and run the following code:
import com.ms.win32.*; 

public class EnvTest 
{ 
	public static void main(String args[]) throws Exception 
	{ 
		// Uncomment the "Thread.sleep(10000); line to work around 
		// this problem. From a command prompt, run "jview EnvTest" 
		// and attach to the process (on the Visual J++ 6.0 Debug 
		// menu, click Processes). Click close on the dialog 
		// box while the thread is sleeping. The IDE debugger will 
		// stop at the first break point. 

		//Thread.sleep(10000); 
		StringBuffer val = new StringBuffer(256); 
		Kernel32.GetEnvironmentVariable("TEMP", val, 256); 
		String output = "The TEMP Environment variable is: ";
		if (val.length() == 0)
			val.append("Not defined.");
		output += val;
		User32.MessageBox(0, output, "Application Message", 0);
		System.out.println("Press the <ENTER> key to continue.");
		System.in.read(); 
	} 
} 
				

RESULT: From the command line, you get C:\TEMP. If you click Start or Start Without Debugging on the Debug menu in a Visual J++ 6.0 project, you get the following error message:
Not defined.

REFERENCES

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbide kbprb KB215413