I am building a project and need to use WebEngine class. So I have 2 projects, MainA and SecondB. The SecondB project is in dependency to MainA, so after building it SecondB becomes a jar file in the MainA libs folder.
Now. I need to open a abc.html file that is under SecondB resources. When testing it locally it works, when building an app and deploying it on server it fails (probably because it is in SecondB jar file). So the code I am using is:
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
ClassLoader classLoader = getClass().getClassLoader();
String s = classLoader.getResource("subfolder/abc.html").toExternalForm();
webEngine.load(s);
The method classLoader.getResource("subfolder/abc.html").toExternalForm();returns a normal url when running the code localy and something like:
file:jar:C:/Something/MainA/libs/SecondB.jar!/subfolder/abc.html
Do you have any ideas how to load this file from a jar? I tried several options I found on SO, but without success
You can create a "resources" package and copy your files to this package and for accessing your file path for example an html you can use this: getClass().getResource("/resources/abc.html").toURI().toString() this provides to get your files url in your created jar. Hope it is useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With