我有两个 SWT 应用程序。从 app 1,我调用 app2:
Runtime.getRuntime().exec("App2.bat");
App2 已运行,但在显示时抛出异常:
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-win32-3740 in java.library.path
no swt-win32 in java.library.path
C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32-3740.dll: The referenced assembly is not installed on your system
Can't load library: C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32.dll
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at com.escapenotes.updater.Checker.run(Checker.java:58)
at com.escapenotes.updater.Runner.main(Runner.java:20)
当我从命令行调用 app2(运行 App2.bat)时,它运行良好,但从 app1 运行时抛出异常。如何从 app1 运行 app2?
这是 App2.bat 的内容:
@echo off
set JH=C:\Program Files\Java\jre6
set CP=C:\Data\Projects\EscapeNotes\extensions\Updater\bin
set XNP="%CP%";"%CP%\commons-logging-1.1.1.jar";"%CP%\aws-java-sdk-1.0.007.jar";"%CP%\commons-codec-1.4.jar";"%CP%\commons-httpclient-3.0.1.jar";"%CP%\jsoup-1.6.2.jar";"%CP%\log4j-1.2.8.jar";"%CP%\text.jar";"%CP%\jface.jar";"%CP%\jfacetext.jar";"%CP%\osgi.jar";"%CP%\runtime.jar";"%CP%\swt.jar"
"%JH%\bin\java.exe" -cp %XNP% com.escapenotes.updater.Runner %1
当我添加 -Djava.library.path
@echo off
set JH=C:\Program Files\Java\jre6
set CP=C:\Data\Projects\EscapeNotes\extensions\Updater\bin
set XNP="%CP%";"%CP%\commons-logging-1.1.1.jar";"%CP%\aws-java-sdk-1.0.007.jar";"%CP%\commons-codec-1.4.jar";"%CP%\commons-httpclient-3.0.1.jar";"%CP%\jsoup-1.6.2.jar";"%CP%\log4j-1.2.8.jar";"%CP%\text.jar";"%CP%\jface.jar";"%CP%\jfacetext.jar";"%CP%\osgi.jar";"%CP%\runtime.jar";"%CP%\swt.jar"
"%JH%\bin\java.exe" -Djava.library.path="C:\Data\Projects\EscapeNotes\extensions\Updater\bin" -cp %XNP% com.escapenotes.updater.Runner %1
虽然有 C:\Data\Projects\EscapeNotes\extensions\Updater\bin\swt-win32-3740.dll,但我得到了异常:
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
C:\Data\Projects\EscapeNotes\extensions\Updater\bin\swt-win32-3740.dll: The referenced assembly is not installed on your system
no swt-win32 in java.library.path
C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32-3740.dll: The referenced assembly is not installed on your system
Can't load library: C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32.dll
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at com.escapenotes.updater.Checker.run(Checker.java:58)
at com.escapenotes.updater.Runner.main(Runner.java:20)