java - Signing JAR to allow its classes to have internet access -


i have java application requires internet access since embeds web browser means of webview javafx component.

if application not packaged in jar, executes without problems. however, when packaged in jar cannot access internet anymore (e.g., cannot load remote javascript files requires, such jquery).

i tried fix signing jar with:

jarsigner myjar myalias 

and command succeeds, although following warning:

warning: signer certificate expire within 6 months. no -tsa or -tsacert provided , jar not timestamped. without timestamp, users may not able validate jar after signer certificate's expiration date (2014-07-08) or after future revocation date.

however, application still not have internet access (the embedded browser still cannot load remote script files). supposed sign in other way ? maybe including certificate recognized certificate authority ?

i have configured permissions in ~/.java.policy file follows:

keystore "file:<userpath>/.keystore", "jks";  grant signedby "myalias" {   permission java.security.allpermission; }; 

i trying in osx 10.9.2 , java 1.8.0-b132

update

it turned out embedded browser executed differently if application embedded in jar or not, , goes beyond security permissions.

i not have idea reason of this, can lead sort of wrong conclusions if not know it. nasty bug probably.

for example, 1 of things observed, when no packaged in jar, beginning embedded web page worked fine:

<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> ... 

but when packaged in jar gave me problems (probably xhtml1-strict enforced) had replace simple <html> tag.

this not different behaviour, main thing giving me problems.

more information great, trying deploy native packaging, using webstart, etc..

anyhow, based on question, i'd suggest take @ letting netbeans signing etc.

i prefer creating fxml based application, way code & interface stays separate. in case i'm throwing in html directly.

i've deployed number of javafx applications using webview no problem. if you're deploying locally, wouldn't worry certificate expiring @ point, unless you're using webstart.

here's sample code works fine, uses webview & accesses internet jquery.

the main class:

import javafx.application.application; import javafx.fxml.fxmlloader; import javafx.scene.parent; import javafx.scene.scene; import javafx.stage.stage;  /**  *  * @author sam  */ public class webviewtestjdk8 extends application {      @override     public void start(stage stage) throws exception {         parent root = fxmlloader.load(getclass().getresource("fxmldocument.fxml"));          scene scene = new scene(root);          stage.setscene(scene);         stage.show();     }      /**      * @param args command line arguments      */     public static void main(string[] args) {         launch(args);     }  } 

the controller:

import java.net.url; import java.util.resourcebundle; import javafx.application.platform; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.label; import javafx.scene.web.webengine; import javafx.scene.web.webview;   public class fxmldocumentcontroller implements initializable {      @fxml     private webview webview;      @override     public void initialize(url url, resourcebundle rb) {          platform.runlater(new runnable() {             @override             public void run() {                 string html = "<html>\n"                         + "<head>\n"                         + "<title>jquery hello world</title>\n"                         + " \n"                         + "<script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-1.2.6.min.js\"></script>\n"                         + " \n"                         + "</head>\n"                         + " \n"                         + "<body>\n"                         + " \n"                         + "<script type=\"text/javascript\">\n"                         + " \n"                         + "$(document).ready(function(){\n"                         + " $(\"#msgid\").html(\"hello world jquery\");\n"                         + "});\n"                         + " \n"                         + "</script>\n"                         + " \n"                         + "hello world html\n"                         + " \n"                         + "<div id=\"msgid\">\n"                         + "</div>\n"                         + " \n"                         + "</body>\n"                         + "</html>";                  webview.getengine().loadcontent(html);             }         });      }  } 

the fxml:

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.web.*?>  <anchorpane id="anchorpane" fx:id="pane" prefheight="367.0" prefwidth="446.0" xmlns:fx="http://javafx.com/fxml" fx:controller="webviewtest.jdk8.fxmldocumentcontroller">   <children>     <webview fx:id="webview" prefheight="367.0" prefwidth="446.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0" />   </children> </anchorpane> 

hope helps!


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -