JNI with SDK 1.4
With SDK 1.4 it is not possible to get environment variables with System.getenv(String
name), because this method is deprecated. This DLL implements the getenv method
again and a method for getting the Windows platform id.
To create your own JNI project with SDK 1.4 and .DOT, first write the java
class, compile it and create the JNI-header:
- javac de\frankbuss\jni\WinAccess.java
- javah de.frankbuss.jni.WinAccess
Then start the .NET-IDE and create a new project:
- New Project->Win32 Project
- Win32 Application Wizard->Application Settings: DLL
- Configuration-Properties -> C/C++ -> General -> Additional Include
Directory: C:\j2sdk\include;C:\j2sdk\include\win32
- Configuration-Properties -> Linker -> General -> Additional Library
Directories: C:\j2sdk\lib
- Configuration-Properties -> Linker -> Input -> Additional Dependencies:
jvm.lib
- optional: Configuration-Properties -> All Configuration -> C/C++ ->
Precompiled Headers -> Create/Use Precompiled Header: Not Using Precompiled
Headers
- copy the native function prototypes to your cpp-file and implement the functions
Here's the example for getting the environment values and the platform name:
Full project, with .NET project files: jni.zip
For starting the test enter in a DOS-box:
java de.frankbuss.jni.WinAccess
On my Windows XP system I can see the following output:
Win32 on Windows NT/Windows 2000
C:\WINDOWS
27 . Juni 2002, Frank Buß