开发者

JNLP File Association: How do I open the file which was double-clicked on?

I've got the following JNLP:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc//DTD JNLP Descriptor 6.0.10//EN" "http://java.sun.com/dtd/JNLP-6.0.10.dtd">
<jnlp spec="6.0.10" version="1.63" codebase="http://foo.example.com/msi" href="Foo.jnlp">
    <information>
        <title>Foo</title>
        <vendor> Foo Systems, Inc.</vendor>
        <homepage href="http://Foo.com"/>
        <description>Foo Viewer/Editor Application</description>
        <icon href="splash.gif" width="425" height="102" kind="splash"/>
        <icon href="Foo.gif" width="64" height="64"/>
        <offline-allowed/>
        <shortcut>
            <desktop/>
            <menu submenu="Foo Systems, Inc."/>
        </shortcut>
        <association mime-type="application-x/wlog" extensions="wlog"/>
        <association mime-type="application-x/mplot" extensions="mplot"/>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.6+" initial-heap-size="32m" max-heap-size="255m"/>
        <jar href="jars_deployment/TimingFramework-1.0.jar"/>
        <jar href="jars_deployment/iText-2.1.5.jar"/>
        <jar href="jars_deployment/jai_codec.jar"/>
        <jar href="Foo.jar"/>
        <jar href="jars_deployment/TimingFramework-1.0.jar"/>
        <jar href="jars_deployment/iText-2.1.5.jar"/>
        <jar href="jars_deployment/jai_codec.jar"/>
        <jar href="jars_deployment/jsch-20090402.jar"/>
        <property name="apple.laf.useScreenMenuBar" value="true"/>
        <property name="apple.awt.graphics.UseQuartz" value="false"/>
        <property name="com.apple.mrj.application.apple.menu.about.name" value="Foo"/>
        <property name="java.util.logging.config.file" value="/Users/Shared/logging.properties"/>
    </resources>
    <application-开发者_开发问答desc main-class="com.prosc.msi.editor.ui.test.Sandbox"/>
</jnlp>

Most everything is working. When I double-click a .wlog file, it opens up my application. However, it doesn't open the correct file. I read somewhere that JNLP was supposed to pass parameters to the main method indicating which file caused the app to be launched, but this is not happening (on OS X 10.6). I get an empty array to my application's main method.

Probably unrelated, my splash screen doesn't work :(

Any pointers on getting this working?


In a bundled application on Mac OS X, you can implement com.apple.eawt.ApplicationListener, as shown in the Mac OS X Reference Library example, OSXAdapter:

The sample also supports document handing from the Finder by implementing the handleOpenFile() method and registering for supported file types in its Info.plist file.

Addendum: com.apple.eawt.ApplicationListener is deprecated; instead consider com.apple.eawt.Application, which provides getApplication().setOpenFileHandler().


About the splash window

I think the app is just missing the right path to your images. In this case, like you mention the codebase:

<jnlp spec="6.0.10" version="1.63" codebase="http://foo.example.com/msi" href="Foo.jnlp">

and like you said in the image: <icon href="splash.gif" width="425" height="102" kind="splash"/>

then, your images have to be in http://foo.example.com/msi/splash.gif

You might want be sure images are in that place.... is what I'm thinking could be the cause.


About the file association.

I'm working right now in the same, and it was seeming to be working while adding a Service from the JNLP API SingleInstanceService. This service is used to register the application like a singleton instance. So, any time your application is lauched, it could retreive the parameters which were used to call you app. In this case, you can use it to see the name of the file that was double clicked on. http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/examples.html#SingleInstanceService In page above you can find an example and a breaf explanation about that service.

The problem that I found with that, is that I could not see the file name the first time that you run the app. I mean, this service should register the app the first time, and after this time, you will be seeing the parameters used to launch the app. So, with this service if you opened the first time your app through a double click on your associated file, you will miss the parameters, until the next double click on it. Your app now will not open another instance again, just will pass the parameters to the instantiated application.

So, I found another solution for this.

http://www.knowledgesutra.com/discuss/tpclso-implement-single-instance-application-java.om

The boy in the page above, used a jar file from inside the Java installation to see the VM instance running that was invoked to see the parameters of the launch of your app. It has the code and the jar used to do that in this same page.

Now I'm able to see the line that was calling the app, like this:

com.sun.javaws.Main -open C:\\JNLP example\\applet-cartoon\\drawingPack\\drawing_monitor\\ejemplo.ply C:\Users\IsraelAltamira\AppData\Local\Temp\javaws23

where ejemplo.ply is the file extension that I used in the jnlp descriptor.

And well, Im working in OS X 10.6.4 now, and it seems to work, but at this moment the web start is not doing me the file association, and is not doing the shortcuts to the installed app... but maybe this last solution works for both systems (at least it work from my fake hyperlink, like the line above to open the file).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜