1

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:

working

Not-working screenshot after exporting as a JAR:

not working

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!

ryanwc
  • 179
  • 1
  • 11
  • Are all your pictures / resources and libs within the project or do you have them all around your disk? Do you use relativ or absolute paths? – Peter Feb 11 '16 at 15:04
  • All resources that are on my computer are in the project and use relative paths. I added an update to the end of the question if you want to take a look. – ryanwc Feb 11 '16 at 17:33
  • Do you reference any url with `file:`? Like in http://stackoverflow.com/questions/28724478/javafx-image-loading-error? Are you unsing a WebView to display this `.html` file? – Peter Feb 12 '16 at 08:10
  • Yes, Eclipse references the `.html` url with `file:`. So, when printing the getClass() portion of `webengine.load(getClass().getResource(htmlFile).toExternalForm());`, Eclipse prints `file:/absolutepath/index.html` but the JAR prints `relativepath/index.html`. Yes, I use a WebView to display the `.html` file. So the logic goes like this: `webview = new WebView();` ; `webengine = new JavaFxWebEngine(webview.getEngine());` ; `JavascriptRuntime.setDefaultWebEngine(webengine);` ; `webengine.getLoadWorker()[etc]` ; `webengine.load(getClass().getResource(htmlFile).toExternalForm());` – ryanwc Feb 12 '16 at 11:21
  • And then once that code is executed, I add a `mapInitializedListener` to the created `mapComponent`, which is `GoogleMapView` object. Inside the JAR, the `mapInitializedListener` recognizes when the view is initialized and fires the code in the `mapInitialized()` method, which includes options like a center latitude/longitude to pass to `map = mapComponent.createMap(options)`, which creates a google.maps.Map JavaScript object with options. Then the next line sets up alerts on the WebView. This is the point in Eclipse where the Google Map shows up, but it does not show up in the JAR version. – ryanwc Feb 12 '16 at 11:52

1 Answers1

0

I guess this would not fit into the comment. My projectstructure for a simular program is like this:

    C:.
    └───src
        ├───main
        │   ├───java
        │   │   └───com
        │   │       └───domain
        │   │           └───d3project
        │   │               └───adapter
        │   └───resources
        │       └───com
        │           └───domain
        │               └───d3project
        │                   ├───JavaScript
        │                   ├───JSON
        │                   ├───pictures
        │                   ├───index.html 
//                                ^  index in resource folder                             
        │                   └───Styles
        │                       └───images
        └───test
            └───java
                └───com
                    └───domain
                        └───d3project
                            └───adapter

Under src/main I have a folder java and resources as long as the have the same packages I can load my index.html like this:

webView = new WebView();
webEngine = webView.getEngine();
try {
    webEngine.load(getClass().getResource("index.html").toExternalForm());
} catch (Exception e) {
     e.printStackTrace();
}

I don't know if this solves your problem or helps in any way, but it was one of the problems I faced when setting up my project. This helped me.

Community
  • 1
  • 1
Peter
  • 1,844
  • 2
  • 31
  • 55
  • Hmm. I will have to take a closer look, but I'm not sure about this. If my problem were similar to yours, wouldn't the JAR version throw an exception when trying to access the `.html` file or create any of the objects based on or access any of the code in the `.html` file? – ryanwc Feb 12 '16 at 12:20
  • It proabably would, I guess this goes beyond my scope :-/ – Peter Feb 12 '16 at 12:24