这是我的第一个问题,所以我希望能够清楚。 我正在开发一个简单的JavaFX应用程序,它唯一要做的就是显示一个Web用户界面。 一切似乎都没问题,我从Eclipse导出了Runnable JAR文件,我在Window 10和7上测试了它,但是当我把jar放在Window XP操作系统上时,我有以下内容:
Exception in Application start method Exception in thread "main" java.lang.reflect.InvocationTargetException 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 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa der.java:58) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm pl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155( LauncherImpl.java:182) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.UnsatisfiedLinkError: Invalid URL for class: rsrc:com/sun/g lass/utils/NativeLibLoader.class at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoad er.java:162) at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoad er.java:94) at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java: 39) at com.sun.webkit.WebPage.lambda$static$39(WebPage.java:130) at java.security.AccessController.doPrivileged(Native Method) at com.sun.webkit.WebPage.<clinit>(WebPage.java:129) at javafx.scene.web.WebEngine.<init>(WebEngine.java:879) at javafx.scene.web.WebEngine.<init>(WebEngine.java:866) at javafx.scene.web.WebView.<init>(WebView.java:273) at application.Main.start(Main.java:30) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162 (LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Platfor mImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl. java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformI mpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatch er.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.ja va:191) ... 1 more
这是我的代码:
package application;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebEvent;
import javafx.scene.web.WebView;
public class Main extends Application {
@Override
public void start(Stage stage)
{
stage.setMinWidth( 800 );
stage.setMinHeight( 600 );
stage.setMaximized( true );
Scene scene = new Scene(new Group());
WebView browser = new WebView();
WebEngine we = browser.getEngine();
//setting personalized context menu
browser.setContextMenuEnabled( false );
//createContextMenu( browser );
//preventing bug when maximmizing
stage.maximizedProperty().addListener(new ChangeListener<Boolean>()
{
@Override
public void changed( ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1 )
{
System.out.println("maximized:" + t1.booleanValue());
}
});
//intercepting javascript alert
browser.getEngine().setOnAlert( new EventHandler<WebEvent<String>>()
{
@Override
public void handle(WebEvent<String> e)
{
Alert alert = new Alert( AlertType.WARNING );
alert.setTitle( "MyApp" );
alert.setHeaderText( null );
alert.setContentText( e.getData() );
alert.showAndWait();
System.out.println("JS alert() message: " + e.getData() );
}
});
//intercepting javascript confirm
browser.getEngine().setConfirmHandler( new Callback<String, Boolean>()
{
@Override
public Boolean call( String s )
{
Boolean ret;
ButtonType ok, cancel;
ok = new ButtonType( "Ok" );
cancel = new ButtonType( "Abort" );
Alert alert = new Alert( AlertType.CONFIRMATION );
alert.setTitle( "SameLAB" );
alert.setHeaderText( s );
alert.setContentText( null );
alert.getButtonTypes().setAll( ok, cancel );
alert.showAndWait();
if( alert.getResult() == ok )
ret = true;
else
ret = false;
return ret;
}
});
ScrollPane sp = new ScrollPane();
sp.setFitToWidth( true );
sp.setFitToHeight( true );
sp.setContent(browser);
//loading and showing content
we.load("https://www.google.it/");
scene.setRoot( sp );
stage.setScene( scene );
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
希望有人帮助我,谢谢!
答案 0 :(得分:0)
升级到最后一个JDK 121后,我今天遇到了这个问题。 同样的问题是早期发布JDK 122。
至于现在WebView和HTMLEditor在使用JDK 77时可能正常工作(可能还有一些更新版本(如下面链接中所述 - 102),但我没有检查它)。 问题是加载库NativeLibLoader.loadLibrary(&#34; jfxwebkit&#34;); 有一些模糊的建议,一些新的Microsoft Visual C ++ Redistributables可能会有所帮助。
编辑。 它已经在bug报告中了:https://bugs.openjdk.java.net/browse/JDK-8170084并且,唉,以决议结束:&#34;赢得了修复&#34;。
因此,剩下一个选项 - 为Windows XP提供捆绑的JRE版本1.8.0_102或更低。
答案 1 :(得分:0)
因此,剩下一个选项 - 为Windows XP提供捆绑的JRE版本1.8.0_102或更低版本。另一个临时脏选项:将应用程序与1.8.0_102中的jfxwebkit.dll捆绑在一起,并在创建WebView实例之前在代码中添加某个地方(例如,在start(Stage primaryStage)方法中)
if ("Windows XP".equals(System.getProperty("os.name"))){
System.load(ABS_PATH_TO_JFXWEBKIT_DLL + "\\jfxwebkit.dll");}