NOTE: The issue does not seem to be with accessing resources. No exceptions are thrown or warnings given when trying to access the relevant resources. I've spent two days troubleshooting this issue, and now this question is the first AND second hit on Google when you search "javafx google map does +not work in JAR".
I have a project that works in Eclipse but not when exported as a JAR. It uses JRE 1.8.0_65, JavaFX, GMapsFX, and references the javax.json-1.0.4.jar library. I am on a Mac running OS X 10.9.5.
The project is a re-creation of some of Google Map's path finding capabilities. It uses a GUI built with JavaFX and GMapsFX that interfaces with Google Maps.
When I export the project as a JAR and run the JAR, nothing appears in the portion of the GUI dedicated to showing Google Maps and allowing the user to select location markers to add to the path. Note that the interactive Google Map should be present upon startup, and then markers are added after the user loads some data. Here are some screenshots for illustration:
Working screenshot when running in Eclipse:
Not-working screenshot after exporting as a JAR:
The URL to the Google Map API is in a file in the project called "index.html". I tested, and the JAR properly loads this file. Further, the JAR correctly loads data files and creates marker objects to add to the display based on those data files.
So, the problem is the JAR is not displaying the interactive Google Map and markers built from data files that should be placed on the Google Map. Why???
A skeleton of the logic to load the Goole Map looks like this:
GoogleMapView mapComponent =
(
webview = new WebView();
webengine = new JavaFxWebEngine(webview.getEngine());
JavascriptRuntime.setDefaultWebEngine(webengine);
webengine.getLoadWorker()[etc];
webengine.load(getClass().getResource(htmlFile).toExternalForm()); // the variable "htmlFile" is "/html/index.html" and seems to be access properly by both Eclipse and the JAR.
)
mapComponent.addMapInitializedListener();
[the mapComponent is initialized and so the mapInitilized() function fires]
MapOptions options = [some options to pass the GoogleMap constructor, such as a zoom level and a center]
GoogleMap map = mapComponent.createMap(options);
At this point, the Eclipse project displays a Google Map with the given options, and the JAR version shows blank white space where there should be a Google Map with the given options.
I have tried each of the three options for including referenced libraries when exporting the project as a runnable JAR from Eclipse, and I have included both the JRE runtime library and the javax.json referenced library in the export build path.
The only errors I get when running the JAR, no matter what I do or where I click, are the following:
com.sun.javafx.css.StyleManager getCachedImage
WARNING: Error loading image: rsrc:dialog-error.png
com.sun.javafx.css.StyleManager getCachedImage
WARNING: Error loading image: rsrc:dialog-information.png
Those errors come from an alert box that pops up when I click "display route" with no start or stops selected, and don't seem related to the Google Map not showing up.
Here is a link to a GitHub repo where you can inspect the entire code: https://github.com/ToolsForInsight/GraphSearch
Any ideas what the problem is? I can provide more details and some code if it would be helpful. Thank you!