Today I'm going to show you how to use C# dll file in Java project (I used Visual Studio & NetBean) with JNI4NET. Actually there are 2 common methods for this problem: JNI4NET & JAVONET. But Javonet is a paid solution & I don't like this :3
Requirement:
- Java JDK, .NET SDK,
- add csc.exe & javac.exe to the PATH
- Visual Studio
- Java IDE (netbean, eclipse,...)
- lib files: jni4net.j-0.8.8.0.jar, jni4net.j-0.8.8.0.dll, jni4net.n.w64.v40-0.8.8.0.dll, yourLib.dll
- build tool: proxygen.exe, proxygen.exe.config & cmd file to run proxygen.
Creating proxies:
- put necessary files to a folder "create lib"
- run "create proxies.cmd", it will run proxygen.exe
- run "build.cmd" in folder "output"
- copy 2files: "yourLib.j4n.dll" & "yourLib.j4n.jar" to folder "lib"
- copy lib files into folder "lib"
Importing:
we have 6 files in previous steps:
- jni4net.j-0.8.8.0.jar,
- jni4net.j-0.8.8.0.dll,
- jni4net.n.w64.v40-0.8.8.0.dll (depending your OS, 32bit or 64bit)
- yourLib.dll (original dll file)
- yourLib.j4n.dll
- yourLib.j4n.jar
-->
Copy them into your java project & import 2 jar file into libraries.
Here is an example:
1. Create a simple dll file - plamduyLib.dll:
2. Put all necessary file into a folder:
Commands in "create proxies.cmd" are:
proxygen.exe plamduyLib.dll -wd outputnote:
timeout /t -1
- proxygen.exe : location of tool
- plamduyLib.dll: location of dll file
- output: folder named output
--> run this cmd file, it create some files in "output" folder.
run "build.cmd" result 2 files dll & jar:
well, we have 6 files:
3. Create java project:
Here are 2 project:
Have a 9day!






No comments:
Post a Comment