PRB: Environment Variables Are Lost When Running from VJ6 IDE


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.


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.


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).


This behavior is by design.


Steps to Reproduce Behavior

Compile and run the following code:
import*; 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.");; } } 

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.


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

ID članka: 215413 - posljednja izmjena: 14. velj 2017. - verzija: 1

Microsoft Visual J++ 6.0 Standard Edition

Povratne informacije