2012-01-12 7 views
5

Tôi đang sử dụng thư viện a Hyperic SIGAR làm lib của bên thứ ba trong chương trình cài đặt của mình. Chương trình cài đặt của tôi mở gói tất cả các tệp lib thứ ba vào thư mục người dùng% TEMP% \\."không có sigar-x86-winnt.dll trong java.library.path" lỗi khi sử dụng Hyperic SIGAR trên hệ điều hành đa ngôn ngữ

Mở tất cả mọi thứ bằng tiếng Anh hệ điều hành hoạt động tuyệt vời, nhưng khi tôi đã cố gắng để chạy chương trình cài đặt của tôi trên Os Tây Ban Nha, tôi đã gặp phải lỗi sau:

thư viện java bao gồm các sigar.jar:

java.class.path = C: \ DOCUME ~ 1 \ Tây Ban Nha Letters \ CONFIG ~ 1 \ Temp \ e4j58.tmp_dir \ user \ sigar.jar

chương trình cài đặt của tôi hỗ trợ WinXP, WIN7 hệ điều hành.

Các Lỗi là:

no sigar-x86-winnt.dll in java.library.path 
org.hyperic.sigar.SigarException: no sigar-x86-winnt.dll in java.library.path 
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172) 
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100) 
at I4jScript_Internal_1.eval(I4jScript_Internal_1.java:23) 
at I4jScript_Internal_1.evaluate(I4jScript_Internal_1.java:79) 
at com.install4j.runtime.installer.helper.Script.evaluate(Unknown Source) 
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source) 
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source) 
at com.install4j.runtime.beans.actions.control.RunScriptAction.execute(Unknown Source) 
at com.install4j.runtime.beans.actions.SystemInstallOrUninstallAction.install(Unknown Source) 
at com.install4j.runtime.installer.InstallerContextImpl.performActionInt(Unknown Source) 
at com.install4j.runtime.installer.ContextImpl.performAction(Unknown Source) 
at com.install4j.runtime.installer.controller.Controller.executeActions(Unknown Source) 
at com.install4j.runtime.installer.controller.Controller.handleCommand(Unknown Source) 
at com.install4j.runtime.installer.controller.Controller.handleStartup(Unknown Source) 
at com.install4j.runtime.installer.controller.Controller.start(Unknown Source) 
at com.install4j.runtime.installer.Installer.main(Unknown Source) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.exe4j.runtime.LauncherEngine.launch(Unknown Source) 
at com.exe4j.runtime.WinLauncher.main(Unknown Source) 
at com.install4j.runtime.launcher.WinLauncher.main(Unknown Source)' 

Có ai đã gặp phải một lỗi tương tự và có thể tư vấn? Cảm ơn.

+0

thử ví dụ này để tải các tập tin [1]: http://stackoverflow.com/questions/4691095/java-loading-dlls -by-a-relative-path-and-hide-them-inside-a-jar – Kris

Trả lời

1

SIGAR-x86-winnt.dll đặt trong hiện tại thư mục người dùng, nó sẽ hoạt động

+0

Bạn có thể cho biết nơi tôi có thể lấy sigar-x86-winnt.dll không? – Jet

+0

@Jet - Bạn đã thử googling cho nó chưa? –

+0

@StephenC ... vâng tôi hiểu nó bằng cách nào đó – Jet

1

như được thảo luận trong các tài liệu, SIGAR sử dụng JNI bên dưới. Bạn phải bao gồm tệp JNI thích hợp trong đường dẫn (tệp thường được hiển thị trong theo dõi ngăn xếp). Nếu bạn đang sử dụng maven để xây dựng dự án, bạn nên chỉnh sửa pom.xml để thêm tập tin này vào đường dẫn (than ôi, bạn không thể xác định vật và cho rằng nó sẽ là trong đường dẫn)

<!-- add sigar dll to java path --> 
       <configuration> 
        <forkMode>once</forkMode> 
        <workingDirectory>target</workingDirectory> 
        <argLine>-Djava.library.path=${basedir}/lib</argLine> 
       </configuration> 
1

Bạn có thể cũng thêm vào java.path.library khi chạy theo chương trình.

System.setProperty("java.library.path", System.getProperty("java.library.path")+File.pathSeparator+pathToYourDLL); 

    //set sys_paths to null 
    final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths"); 
    sysPathsField.setAccessible(true); 
    sysPathsField.set(null, null); 

Một lời giải thích rất tốt được tìm thấy tại địa chỉ: http://fahdshariff.blogspot.jp/2011/08/changing-java-library-path-at-runtime.html