簡體   English   中英

使用JavaFx WebEngine加載本地文件並將參數添加到url。 從jar執行程序時不起作用

[英]Using JavaFx WebEngine to load a local file and adding parameters to the url. Not working when executing program from jar

我一直在編程一個GUI,以顯示來自傳感器的數據。

該gui包括一個Google地圖可視化工具,可顯示帶有標記的數據(通過GPS讀數)。

我一直在使用“?”通過URL傳遞讀數。 和'&':

    String url = this.getClass().getResource("/resources/map.html").toExternalForm();
    url +="?";
    for (GPSReading r : data) {
        // remove all aplhabetic characters, except for S and E (for lon
        // lat) then trim the white spaces
        // pass it into the url to be processed by js
        url += r.toString().trim().replaceAll("[^\\d.ES ]", "").replaceFirst("S", "");
        url += '&';
    }

然后將其加載到WebEngine中

webEngine.load(url);

在eclipse中運行時,此方法工作正常,但是當我將代碼打包到可執行jar中時,鏈接斷開,並且webEngine上沒有任何顯示。

這是我從url中檢索參數的js代碼:

    var parameters = window.location.href;
    parameters= decodeURI(parameters.split("?")[1]);
    var paramArray = parameters.split('&');
    [...]
     var field = paramArray[reading].split(" ").filter(Boolean);

然后,我繼續進行一些字符串解析,效果很好。

有人知道為什么通過url傳遞參數可以從eclipse起作用,而不是從Jar起作用嗎?

編輯

我檢查了jar,它包含了我使用過的唯一外部庫(RxTx),其余的我都使用了Java標准庫。

您是否檢查了eclipse制成的jar,其中包含您需要的所有必需類和外部庫。 如果沒有外部庫,則可能是一個問題。 然后,您需要為所有依賴項的文件制作一個胖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM