Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does BasicService.getCodeBase() return null when using file:// as URL protocol in the JNLP codebase attribute?
    primarykey
    data
    text
    <p>In a WebStart application, I'm using this code to retrieve programmatically the JNLP codebase:</p> <pre class="lang-java prettyprint-override"><code>package web.start.test; import java.net.URL; import javax.jnlp.BasicService; import javax.jnlp.ServiceManager; import javax.jnlp.UnavailableServiceException; import javax.swing.JOptionPane; public class WebStartTest { public static void main(String[] args) { try { BasicService basicService = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService"); URL codeBase = basicService.getCodeBase(); JOptionPane.showMessageDialog(null, "Code base is: [" + codeBase + "]"); } catch (UnavailableServiceException exception) { throw new RuntimeException(exception); } } } </code></pre> <p>I'm using this JNLP descriptor to start the application:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;jnlp spec="1.0+" codebase="file:/d:/playground/eclipse/WebStartTest" href="WebStartTest.jnlp"&gt; &lt;information&gt; &lt;title&gt;WebStartTest&lt;/title&gt; &lt;vendor&gt;Web Start Tester&lt;/vendor&gt; &lt;/information&gt; &lt;security&gt; &lt;all-permissions/&gt; &lt;/security&gt; &lt;resources&gt; &lt;j2se version="1.7+" /&gt; &lt;jar href="target/WebStartTest-0.0.1-SNAPSHOT.jar" /&gt; &lt;/resources&gt; &lt;application-desc main-class="web.start.test.WebStartTest" /&gt; &lt;/jnlp&gt; </code></pre> <p>After packaging and signing the jar file, hitting Enter on the JNLP file starts the application successfully, but the pop-up message says: <strong>"Code base is: [null]"</strong>.</p> <p>The same code retrieves the codebase properly when deployed in a web server and launched via a JNLP file that uses "http://" instead of "file://" as the codebase protocol.</p> <p>Is there a way to retrieve the codebase of a WebStart application when deployed on a local (or shared network) drive using a JNLP descriptor with a "file://" codebase?</p> <p>If not, how else can I programmatically find the URL to the application directory in order to access resource files (that are not packaged within the jar files)?</p> <p>Moreover, from a best practices standpoint: is deploying a WebStart application in a shared network drive rather than in a web server (for the sake of simplicity) a reasonable approach, or is it rather a hack that should be avoided?</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload