This is the mail archive of the
mailing list for the Cygwin project.
Problem to retrieve environment variable values in JVM when Cygwin prompt is used
- From: "Toke, Mahesh" <mahesh_toke at bmc dot com>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Cc: "Virulkar, Nitin" <Nitin_Virulkar at bmc dot com>, "Badhei, Sankharaj" <Sankharaj_Badhei at bmc dot com>
- Date: Mon, 18 Dec 2017 11:35:07 +0000
- Subject: Problem to retrieve environment variable values in JVM when Cygwin prompt is used
- Authentication-results: sourceware.org; auth=none
We use Cygwin build and its command prompt in our use cases.
Currently, We are facing a problem to retrieve environment variable values in JVM program. Please find details of issue below :
Version details : Currently, cygwin1.7.33 is being used on windows (tried on server 2008R2, server 2012) platform.
Files attached with this mail :
1. SampleJVM.cpp ==> C program which evokes JVM and it calls a java method
2. TestEnvironmentVariables.java and TestEnvironmentVariables.class ==> Java program containing a method to print environment variables.
1. Ensure that jdk is installed on the system.
2. In the SampleJVM.cpp program, LoadLibrary() function loads jvm.dll. Please replace the path with local installation path.
3. -Djava.class.path is set to C:\\temp where TestEnvironmentVariables.class file is kept. Please replace C:\\temp with local disk path where TestEnvironmentVariables.class is kept.
4. Compile the program on cygwin command prompt using : g++ SampleJVM.cpp -o SampleJVM -I"C:\Microsoft\include\jni" -I"C:\Microsoft\include\jni\win32"
Ensure that C:\Microsoft\include\jni and C:\Microsoft\include\jni\win32 are replaced with location of jni.h and jni_md.h file. These files will be present in jdk installation.
5. Execute the program ./SampleJVM on cygwin prompt
PATH, SYSTEMDRIVE, SYSTEMROOT, WINDIR variables are getting printed.
On windows machine, there are many environment variables already set. But they are not getting printed as output of java program.
For example APPDATA variable value is coming null hence not printed on the command prompt.
Same program if built using another compiler (e.g. visual studio) and executed on command prompt then it prints all the environment values.
As a summary, when a C program spawns a JVM and calls java method, then inside java method, we are not able to retrieve environment variable values.
This issue is occurring only when we use Cygwin build and Cygwin command prompt.
I did not find related information on this problem on Cygwin faqs link. It looks like a generic bug with Cygwin build.
Please confirm if you are able to run the sample program and reproduce the issue.
Thanks to update me on its status.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple