Matt Chad Matt Chad - 1 year ago 216
Java Question

Java WebView generate an exception on Windows XP

This is my first question here, so I hope to be clear.
I am developing a simple JavaFX Application, the only thing it has to do is showing a web user interface.
Everything seems to be ok, I exported the Runnable JAR File from Eclipse and I tested it on Window 10 and 7, but when I put the jar on Window XP OS, I have the following:


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



Here is my code:

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);
}
}


Hope that someone cal help me, thank you!

RoK RoK
Answer Source

I encountered this issue today after upgrading to the last JDK 121. The same problem is with early release JDK 122.

As for now WebView and HTMLEditor works fine when using JDK 77 (probably some later versions too (as stated in the link below - 102), but i didn't check out for it). Problem is with loading library NativeLibLoader.loadLibrary("jfxwebkit"); There were some vague suggestions that some new Microsoft Visual C++ Redistributables may help.

Edited. It's already in bugreport: https://bugs.openjdk.java.net/browse/JDK-8170084 and, alas, closed with the Resolution: "Won't Fix".

So, one option is left - provide bundled JRE version 1.8.0_102 or less for Windows XP. Another temporary dirty option: bundle your application with jfxwebkit.dll from 1.8.0_102 and add somewhere in your code before WebView instance created (for example, in start(Stage primaryStage) method)

if ("Windows XP".equals(System.getProperty("os.name"))){ 
System.load(ABS_PATH_TO_JFXWEBKIT_DLL + "\\jfxwebkit.dll");}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download