-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
8u60
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
Windows 7 Ultimate 64 bit SP1
A DESCRIPTION OF THE PROBLEM :
WebEngine does not load a resource file ( javascript, css, image) when this file is referenced from within a html file and when the resource files are packaged in a jar file.
For example this html file that references a javascript file foo.js and loads an image file test.png :
<===== main.html ======>
<html>
<head>
<script type="text/javascript" src="foo.js"></script>
</head>
<body>
This is my editor
<p>
<img src="test.png" alt="test1"/>
</body>
</html>
<=======End of main.html ==============>
The javascript file foo.js in the root folder
<=====foo.js ==============>
var foo;
function foo()
{
}
<=========End of foo.js ======>
Let have an image file test.png
Here the java class test:
<================ TestWebEngine.java ===========>
import javafx.application.Application;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;
public class TestWebEngine extends Application
{
private WebView mWebView;
@Override
public void start(Stage stage)
{
mWebView = new WebView();
WebEngine webEngine = mWebView.getEngine();
setupChangeListeners();
webEngine.load(getClass().getResource("main.html").toExternalForm());
JSObject win = (JSObject) mWebView.getEngine().executeScript( "window" );
win.setMember( "console", new Console() );
stage.setScene(new Scene(mWebView, 1280, 900));
stage.show();
}
private void setupChangeListeners()
{
ChangeListener<Worker.State> webEngineLoadListener = createWebEngineLoadListener();
ReadOnlyObjectProperty<State> webEngineLoadStateProperty =
mWebView.getEngine().getLoadWorker().stateProperty();
webEngineLoadStateProperty.addListener( webEngineLoadListener );
}
private ChangeListener<State> createWebEngineLoadListener()
{
return new ChangeListener<Worker.State>()
{
@Override
public void changed( ObservableValue<? extends State> loadStateProperty,
State oldLoadState,
State newLoadState )
{
switch( newLoadState )
{
case SUCCEEDED:
handleLoadComplete();
break;
default:
return;
}
}
};
}
private void handleLoadComplete()
{
System.out.println( "main.html loaded - checking if foo() is defined" );
executeScript( "console.log(\'foo =\' + foo );" );
}
private Object executeScript( String script )
{
return mWebView.getEngine().executeScript( script );
}
public static class Console
{
public static final String MEMBER_NAME = "console"; //$NON-NLS-1$
public void log( Object message )
{
System.out.println( message );
}
}
public static void main(String[] args)
{
launch(args);
}
}
<============End TestWebEngine.java===============>
REGRESSION. Last worked in version 8u40
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Bundle the provided java class and the resource files in a jar file,
run java -jar file.jar
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The web page is loaded from the html file
The image is loaded from png.test
The foo.js is loaded and the foo() function is defined
ACTUAL -
The web page is loaded from the html file
The image is not loaded
The javascript file is not loaded and the foo() function is not defined
REPRODUCIBILITY :
This bug can be reproduced always.
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
Windows 7 Ultimate 64 bit SP1
A DESCRIPTION OF THE PROBLEM :
WebEngine does not load a resource file ( javascript, css, image) when this file is referenced from within a html file and when the resource files are packaged in a jar file.
For example this html file that references a javascript file foo.js and loads an image file test.png :
<===== main.html ======>
<html>
<head>
<script type="text/javascript" src="foo.js"></script>
</head>
<body>
This is my editor
<p>
<img src="test.png" alt="test1"/>
</body>
</html>
<=======End of main.html ==============>
The javascript file foo.js in the root folder
<=====foo.js ==============>
var foo;
function foo()
{
}
<=========End of foo.js ======>
Let have an image file test.png
Here the java class test:
<================ TestWebEngine.java ===========>
import javafx.application.Application;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;
public class TestWebEngine extends Application
{
private WebView mWebView;
@Override
public void start(Stage stage)
{
mWebView = new WebView();
WebEngine webEngine = mWebView.getEngine();
setupChangeListeners();
webEngine.load(getClass().getResource("main.html").toExternalForm());
JSObject win = (JSObject) mWebView.getEngine().executeScript( "window" );
win.setMember( "console", new Console() );
stage.setScene(new Scene(mWebView, 1280, 900));
stage.show();
}
private void setupChangeListeners()
{
ChangeListener<Worker.State> webEngineLoadListener = createWebEngineLoadListener();
ReadOnlyObjectProperty<State> webEngineLoadStateProperty =
mWebView.getEngine().getLoadWorker().stateProperty();
webEngineLoadStateProperty.addListener( webEngineLoadListener );
}
private ChangeListener<State> createWebEngineLoadListener()
{
return new ChangeListener<Worker.State>()
{
@Override
public void changed( ObservableValue<? extends State> loadStateProperty,
State oldLoadState,
State newLoadState )
{
switch( newLoadState )
{
case SUCCEEDED:
handleLoadComplete();
break;
default:
return;
}
}
};
}
private void handleLoadComplete()
{
System.out.println( "main.html loaded - checking if foo() is defined" );
executeScript( "console.log(\'foo =\' + foo );" );
}
private Object executeScript( String script )
{
return mWebView.getEngine().executeScript( script );
}
public static class Console
{
public static final String MEMBER_NAME = "console"; //$NON-NLS-1$
public void log( Object message )
{
System.out.println( message );
}
}
public static void main(String[] args)
{
launch(args);
}
}
<============End TestWebEngine.java===============>
REGRESSION. Last worked in version 8u40
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Bundle the provided java class and the resource files in a jar file,
run java -jar file.jar
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The web page is loaded from the html file
The image is loaded from png.test
The foo.js is loaded and the foo() function is defined
ACTUAL -
The web page is loaded from the html file
The image is not loaded
The javascript file is not loaded and the foo() function is not defined
REPRODUCIBILITY :
This bug can be reproduced always.
- duplicates
-
JDK-8136466 [regression] [WebView] Load single page application from jar
-
- Resolved
-
- relates to
-
JDK-8136466 [regression] [WebView] Load single page application from jar
-
- Resolved
-