鎶奷ll鏂囦歡鍐欏叆鍒癹ava.library.path涓dll鏀懼湪ConvertWord2HM鐩稿悓鐩綍涓嬶紝榪欎釜鍙互鏄綘鐨勭被鍚?/span>
InputStream inputStream = Test.class.getResourceAsStream(
LIBFILENAME);
final File dllFile = new File(LIBFILENAME);
if (!dllFile.exists()) {
FileOutputStream outputStream = new FileOutputStream(dllFile);
byte[] array = new byte[1024];
int bytesRead = -1;
while ((bytesRead = inputStream.read(array)) != -1) {
outputStream.write(array, 0, bytesRead);
}
outputStream.flush();
outputStream.close();
}
// 鍔ㄦ佸姞杞絛ll
System.load(dllFile.getPath());
// 鍦ㄨ櫄鎷熸満鍏抽棴鐨勬椂鍊欏垹闄ll 榪欓噷鐪嬬潃鐢ㄥ惂
// dllFile.deleteOnExit();
} catch (Throwable e) {
throw new RuntimeException("load Convert.dll error!", e);
}
}
public static void main(String[] args) {
Test.hello();
}
}
榪欎釜鏂囦歡鏄湪鐩綍/home/my/java涓嬬殑
javac Test.java
javah Test //鐢熸垚Test.h
鐒跺悗鑷繁鍐橳est.cpp
.java .h .cpp 榪欎簺鏂囦歡鍚嶅瓧涓瀹氳涓鏍?br />g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -fPIC -shared -o libtest.so Test.cpp // 杞垚浣犳兂瑕佺殑鏂囦歡 鎴戣繖閲屾槸libtest.so 涔熷彲浠ユ槸libtest.dll, 鐪嬩綘浠g爜璋冪敤浠涔堛?br />java Test 灝卞彲浠ヨ繍琛屼簡
鐢⊿ystem.loadLibrary() 涓鐩村姞杞戒笉浜?鍙兘緗戜笂鎵句簡涓姞杞絣ib鐨勪唬鐮?/div>

]]>