0

My project contains a WebView with html and JS resources. When I launch my .jar file, the WebView remains blank, instead of showing a JS map.

Java Code for loading the html:

bridge  = BridgeSingleton.getInstance();
WebEngine engine = webviewmap.getEngine();
URL urlHello = getClass().getResource("/map/map.html");
engine.load(urlHello.toExternalForm());

The html and JS files are stored in "resources" folder. When the program is launched in Eclipse, it works fine, but not in .jar version.

Any idea about the issue?

Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
IdelHamza
  • 15
  • 5
  • does your jar contain item `/map/map.html`? – guleryuz May 08 '18 at 13:08
  • How can I verify this ? because I generated the jar file from Eclipse, so I think it should contain all necessary files. – IdelHamza May 08 '18 at 13:09
  • Do you copy the resource folder when packaging the jar? You can open the jar in any zip application and check if everything you need is there. – Pesho May 08 '18 at 13:10
  • @Pesho how can I do that ? – IdelHamza May 08 '18 at 13:11
  • how do you export jar file? with eclipse menu, with maven etc? – guleryuz May 08 '18 at 13:12
  • See my previous comment, I added before I finished typing. Open the jar file with a zip app (WinZip, WinRar) and check the contents. – Pesho May 08 '18 at 13:13
  • @guleryuz I use eclipse menu, export to JAR file. – IdelHamza May 08 '18 at 13:16
  • ok, then is your `resources` folder is a `source folder`? if not, you can mark it as a source folder by `project properties` `java build path` `Source tab` `add folder` – guleryuz May 08 '18 at 13:17
  • @guleryuz yes it is ! – IdelHamza May 08 '18 at 13:20
  • does your jar contain item `/map/map.html` – guleryuz May 08 '18 at 13:20
  • @Pesho Yes it does too . – IdelHamza May 08 '18 at 13:26
  • @guleryuz yes it does . – IdelHamza May 08 '18 at 13:26
  • It is possible the paths that load javascript and images are not correct when everything is inside a jar file. You can try to copy these resources beside the jar in the same folder and use them. – Pesho May 08 '18 at 13:33
  • Can you explain "works fine" and "not [works fine]"? Is it loading the HTML, and not loading the Javascript? Or is it not loading the FXML at all? – James_D May 08 '18 at 14:48
  • FWIW I ran a quick test and this all seemed to work fine for me. I placed an HTML file and a Javascript file in a folder under `src/main/resources`, and exported to a jar file; the HTML was loaded and was able to reference the Javascript. – James_D May 08 '18 at 14:55
  • (In previous comment, "FXML" should have been "HTML") – James_D May 08 '18 at 15:00
  • @James_D The HTML works but not the JS . – IdelHamza May 09 '18 at 16:49
  • As I said, it works fine for me. I assume you checked the Javascript file is in the Jar file. See if you can create a [MCVE] (one Java file, one HTML file, one JS file), and include it along with your project layout and the resulting jar file layout in the question. – James_D May 09 '18 at 16:51

1 Answers1

0

The problem is resolved: it was an issue with the geoIp API.

IdelHamza
  • 15
  • 5