The Source for Java Technology Collaboration
User: Password:



Hans Muller

Hans Muller's Blog

Using Java Web Start to Launch NetBeans

Posted by hansmuller on January 09, 2006 at 04:21 PM | Comments (24)

About six months ago I had a dream. Not the sort of dream that makes you wake up shrieking or smiling, and not the kind that brings you down from the mountain top or even gets you off the couch. Mine was the kind of dream programmers have. The kind of sloth inspired idea that comes to you while staring at the screen, wondering if there's a way to eliminate all of the mouse clicking and key pressing effort that makes you weary without actually burning calories.

I spend quite a bit of time looking at Java blogs and articles that incorporate lots of source code. Usually there's a link for zip file that contains all of the files the document refers to, and maybe a jar file with a build. Sometimes articles include direct links to source files, however scanning a pile of source code with the web browser isn't terribly appealing. The nicest way to look at code and try out APIs, is to just load everything into a Java IDE like NetBeans. Once that's done it's possible to use the editor and debugger and all of the other IDE features to explore the code. Like a real programmer should. And just like a real programmer, I'm usually too lazy to bother.

So the big idea was to write a web started app that would download a complete NetBeans project, launch NetBeans, and open the key source files in the editor. That way, if someone was reading a blog or an article about some Java project, they could click on a JNLP link - and with no additional effort! - peruse the code from within the IDE. To me, this seems like a civilized way to do business. Sadly, I wasn't able to con one of my colleagues into building such a web started app. Towards the end of last year, as Sun began to slow down in anticipation of the Christmas break, I took a crack at building a NetBeans launcher. You can try it now, by clicking on the handy launch button below. It's a signed application, because it creates a temp file and launches a (NetBeans) process on your machine, so you'll have to click through a security dialog.

To give the example launcher a try, just click the Launch button:

Web started application launch button

The launch app depends on the NetBeans OpenFile module to start the NetBeans IDE, if necessary. Sadly (at the moment) there isn't an "OpenProject" module, so the best I can do is to show a single Java source file. If the launch app is unable to locate an installed copy of NetBeans, it displays a little form that allows choosing the install directory, or downloading the current NetBeans release. I haven't tested launch very carefully (works on my machine :-) which is unwise, since part of the code to find and launch NetBeans is platform specific. It should work on Windows XP and it might work on Linux or the Mac or Solaris. I'd be happy to hear from anyone who's tried it.

The example file downloaded by the launcher, NetBeans.java, deals with figuring out if and where NetBeans is installed. I didn't pick this one file out of pride, it's incomplete and contains some moderately embarrassing hacks. On the other hand, it does all of the important work. The class is used like this:

NetBeans nb = new NetBeans();
nb.initialize();
if (!nb.isInstalled()) {
    // give the user the opportunity to choose
    // the install directory or download NetBeans
}
else {
    File file = new File("C:\MyProject\src\pkg\MyFile.java");
    try {
        nb.openFile(file);
    }
    catch (NetBeans.Failure e) {
        // report the problem to the user
    }
}

The initialize method uses some shameful heuristics to try and figure out where NetBeans was installed. Check out the source code from within the IDE to see what I mean. It would certainly be much nicer to be able to look in a well known (per platform) place to find out what versions of NetBeans were installed and where; maybe in the future that kind of support will emerge.

You can use the launch app on you own web site, just by making a copy of the JNLP file file and replace the URL in argument element at the bottom. The current version links to the example NetBeans.java file:

<argument>http://download.java.net/javadesktop/blogs/hansmuller/launch/NetBeans.java</argument>

You don't need to copy the launch jar files or anything else. Just create a link to your version of launch.jnlp on your site, and make sure your web server is configured to support the JNLP MIME type.

This was originally intended to be a quick project that I'd finish on on the long flight home from Prague back in December. It didn't turn out that way, in part because building (usable) GUIs is always more work than you'd think. It's also because I took the opportunity to get introduced to Matisse. It's been a long time since I've been comfortable writing Swing GUIs with a tool. Using Matisse turned out to be pretty inspiring: it worked well and it greatly simplified the task of evolving a GUI. Using it was a constant reminder of all of the additional desktop app building support that should be in NetBeans. More about that in another blog.

I have a long laundry list of worthy improvements for the NetBeans launcher. I'd be interested to hear what other developers think of it and what you-all think should be changed/improved. Here are a few of TODO items from the top of my list:

  • Download a complete project packed into a jar file and expand that into a temp directory. Open a set of project relative source files in NetBeans.
  • Log errors, and warnings and provide a way to show them.
  • Show the main window roughly in the middle of the screen. And wouldn't it be nice to know which Screen NetBeans was already running on - if there were multiple screens.
  • An "OpenProject" NetBeans module. I've been assured that this wouldn't be so difficult to write. Making sure that it was deployed to the IDE, before the project was launched would be a bit of a trick.

If you'd like to look at the complete NetBeans launch project, you'll find a zip file of the complete project here. I realize that it's more than a little ironic to publish such a link. Hopefully I'll be able to support loading entire projects (not just files) in round two.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Wow, this is one of those eye-opening experiences where, as a web developer, you have to wonder how long it will be before JNLP becomes the popular choice for applications

    Posted by: jhook on January 09, 2006 at 05:13 PM

  • Thanks for the nice feedback! I do think that using Web Start to
    bridge the gap between the web and powerful desktop applications, like
    NetBeans, has a great deal of potential. There's only a hint of it
    here. If applications like NetBeans provided richer "remote control"
    protocols for their trusted colleagues running on the local machine
    (like our web started launch app), one could do a great deal more than just show one file.

    Posted by: hansmuller on January 09, 2006 at 05:33 PM

  • Aside from the concerns you raise here about finding the netbeans installation, there's the (likely) scenario that netbeans may already be running on the machine. There ought to be a way of locating a running instance and telling it to open the project.

    Posted by: richunger on January 09, 2006 at 05:33 PM


  • The bin/netbeans[.exe] command already does as much, it only
    launches NetBeans if there isn't already a NetBeans process running.
    So the web started launch app should just show it's file in
    the running NetBeans process if there is one. Ofcourse I didn't
    exactly run comprehensive tests ... perhaps it's not working
    correctly for you?

    Posted by: hansmuller on January 09, 2006 at 05:38 PM

  • Actually, I tried it with NB already running and it does work.

    Posted by: timboudreau on January 09, 2006 at 05:44 PM

  • BUG: It doesn't work on my Mac. I only have 1.4.x installed, and the launch file requests 1.5.x. Sorry, my Mac is still on 10.3.9 for which Apple doesn't ship 1.5.

    Posted by: robogeek on January 09, 2006 at 08:03 PM

  • It start on Mac OS X 10.4. but can't find a NetBeans copy. I try /Applications/NetBeans.app/Contents/Resources/NetBeans/ and so on but it doesn't work.


    But it is a cool idea!

    Now i only wait for the first time i can start netbeans self over Java Web Start.

    Posted by: lordy on January 09, 2006 at 11:14 PM

  • The basic problem is excellent idea (the typical "Why didn't I think of this before" feeling) and the not (yet) complete first step is a very good start. I hope you can hold on to this problem until you solve the project loading problem and all the other issues.

    Posted by: vagabondx on January 10, 2006 at 01:05 AM

  • Hans--This is a great idea. It works fine on my WinXP/JDK 5/NB 5beta2.

    Some thoughts--right now there is no context for the file. I have 4 projects I am working on concurrently, and when NB launches (or the file is open in the running version), the Projects and Files tabs don't show it anywhere--a little disconcerting. But nice to be able to see the code in one place, would be useful for examples.

    Also, launch for NB is slow, at least on my laptop (Sonoma platform, so pretty recent model); well over a minute. That might limit the effectiveness of this if there is: download files, unpack, launch NB--I may be waiting a few minutes. Don't know a way to address that, but one idea is to have the JNLP prompt the user--would you like to download this for later review? What they download is a JAR file where the manifest has project unpacking information, and it gets downloaded to a "known" location for the NB "Project Reviewer" module. In other words--I want to look at this, don't have time now--store it in some "known" location, and later, open NB, choose from these downloaded packs--then install to a temp directory and review code. The "PR" module :) could have options to unpack to temp, delete from temp, or copy/move to regular directory so I can actually work on the code. One step to link to CVS--and we have portable projects.

    Download project and unpack sounds good--what about an option for the user to save to a given directory? So if I want the source handy, I can choose a useful directory and then work with it (not just browse it) but by default it's a temp directory.

    Last point--this morning I was reading through a guide on installing PHP5 for Windows on Apache (here). I know Ed, the author, and he likes cranking these out; he has his own content-management system to do so (DataPod, very cool). Anyway, would be even cooler if JNLPProjectLauncher could also use some NB module for "step through" and reviewing code--maybe three panes in use: the code editor, a "task list" tree, and a "documentation" panel, describing what is going on. Probably overkill, but thought I should at least mention it.

    This is nice work.

    Patrick

    Posted by: pdoubleya on January 10, 2006 at 01:58 AM

  • Very cool and I'd love to see the idea extended to other file types (or even into an extension mechanism for JWS). Was there any reason for not using the file association to open the file i.e.

    Runtime.getRuntime().exec
    ("rundll32 SHELL32.DLL,ShellExec_RunDLL " + fileName);

    on Windows?


    BTW - On the latest NetBeans QBuild if I close the downloaded file and retry the JNLP link the file opens but NetBeans does not repaint fully so it looks like the file didn't reopen.

    Posted by: luano on January 10, 2006 at 02:11 AM

  • Patrick: to make it faster maybe pack200 help. WebStart and 29 seconds

    Posted by: lordy on January 10, 2006 at 02:26 AM


  • > Posted by: lordy on January 09, 2006 at 11:14 PM It start on Mac OS
    > X 10.4. but can't find a NetBeans copy. I try
    > /Applications/NetBeans.app/Contents/Resources/NetBeans/
    > and so on but it doesn't work.
    > ...


    Sorry about that. I didn't really test the app on a Mac.
    The initialization code is expecting to find "bin/netbeans"
    in whatever NetBeans install directory you specified.
    I thought that was /Applications/NetBeans.app/? Does
    "/Applications/NetBeans.app/bin/netbeans" exist on your
    machine?

    Posted by: hansmuller on January 10, 2006 at 10:36 AM


  • > Posted by: vagabondx on January 10, 2006 at 01:05 AM
    > ...
    > I hope you can hold on to this problem until you solve the project
    > loading problem and all the other issues.


    I hope to continue to make incremental improvements. It might make
    sense to house the project on javadesktop.org.

    Posted by: hansmuller on January 10, 2006 at 10:36 AM


  • > Posted by: pdoubleya on January 10, 2006 at 01:58 AM
    >
    > Some thoughts--right now there is no context for the file. I have 4
    > projects I am working on concurrently, and when NB launches (or the
    > file is open in the running version), the Projects and Files tabs
    > don't show it anywhere--a little disconcerting. But nice to be able
    > to see the code in one place, would be useful for examples.


    I completely agree; I'd really wanted to download and show a
    project, not just a file. Doing so will take some support
    on the NetBeans side (I've been assured that it wouldn't
    be difficult). I'd really like a developer to be able
    to take a look at the project and then hit F6 and try running
    it, and then make some random changes, try again, etc.


    > Also, launch for NB is slow, at least on my laptop (Sonoma platform,
    > so pretty recent model); well over a minute. That might limit the
    > effectiveness of this if there is: download files, unpack, launch
    > NB--I may be waiting a few minutes. Don't know a way to address that,
    > but one idea is to have the JNLP prompt the user--would you like to
    > download this for later review? What they download is a JAR file where
    > the manifest has project unpacking information, and it gets downloaded
    > to a "known" location for the NB "Project Reviewer" module. In other
    > words--I want to look at this, don't have time now--store it in some
    > "known" location, and later, open NB, choose from these downloaded
    > packs--then install to a temp directory and review code. The "PR"
    > module :) could have options to unpack to temp, delete from temp, or
    > copy/move to regular directory so I can actually work on the code. One
    > step to link to CVS--and we have portable projects.


    I agree that the overall process takes too long. On my less than 2 years
    old laptop, once the Launch app has been cached, it takes nearly 90 seconds
    to show a file if NetBeans isn't running, but less than 10 seconds if NetBeans
    is up. If web start has to download the launch app's jar files first,
    start time takes just a few seconds more (for me) with a decent internet
    connection. With Sun's constipated internal proxy servers in the way,
    it takes considerably longer to download the app's 80K jar file,
    as well as the Matisse layout and SwingWorker jars, which weigh
    in at less than 150K.


    An option for specifying a location to store downloaded "preview"
    projects and support for caching them but not immediately showing
    the files sounds like a reasonable idea.


    The original inspiration for this project was someone's
    enthusiasm-sapping description of how to get access to their
    new project using CVS. Automating that in the way that
    the current launch app automates grabbing a single source
    file is a long term goal.


    > Download project and unpack sounds good--what about an option for
    > the user to save to a given directory? So if I want the source
    > handy, I can choose a useful directory and then work with it (not
    > just browse it) but by default it's a temp directory.


    I did make the temp directory field a read-only JTextField to simplify
    grabbing the download file by copy and pasting the path (a very tiny
    bit). Making it easy to put a download project or file where you want
    in the first place is a good idea.


    > Last point--this morning I was reading through a guide on installing
    > PHP5 for Windows on Apache (here). I know Ed, the author, and he
    > likes cranking these out; he has his own content-management system
    > to do so (DataPod, very cool). Anyway, would be even cooler if
    > JNLPProjectLauncher could also use some NB module for "step through"
    > and reviewing code--maybe three panes in use: the code editor, a
    > "task list" tree, and a "documentation" panel, describing what is
    > going on. Probably overkill, but thought I should at least
    > mention it.


    Support for collaboration tools, like structured code review, doesn't
    seem like overkill (for an IDE) to me. I don't think this project
    will grow into that, although it would be nice if it could start such a
    process.

    Posted by: hansmuller on January 10, 2006 at 10:41 AM

  • Ah, I tried again, and it did work for me, opening the source file in my already-opened IDE instance. I was thrown the first time I tried it, because I use an unzipped IDE on windows (no registry entries), and when I typed "c:\netbeans" and clicked "Try Again", it opened a file dialog instead of trying the path I'd just typed in. If I use the file dialog to select the same directory, it then works.

    Posted by: richunger on January 10, 2006 at 12:14 PM


  • > Posted by: luano on January 10, 2006 at 02:11 AM
    > Was there any reason for not using the file association to open the
    > file i.e.
    > Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + fileName);
    > on Windows?


    I don't believe NetBeans installs a file association for ".java" or
    any other file types. On my machine, applying ShellExec_RunDLL to a
    .java file this just pops up the file in Notepad. I'm not much of a Win32
    programmer (this was the first I'd heard of this particular idiom) so
    if let me know if I'm missing something.


    > BTW - On the latest NetBeans QBuild if I close the downloaded file
    > and retry the JNLP link the file opens but NetBeans does not repaint
    > fully so it looks like the file didn't reopen.


    I have occasionally seen this problem with Netbeans 5.0b2 as well.
    I need to file a bug.


    Posted by: hansmuller on January 10, 2006 at 02:31 PM


  • > Posted by: richunger on January 10, 2006 at 12:14 PM
    > Ah, I tried again, and it did work for me, opening the source file
    > in my already-opened IDE instance. I was thrown the first time I
    > tried it, because I use an unzipped IDE on windows (no registry
    > entries), and when I typed "c:\netbeans" and clicked "Try Again", it
    > opened a file dialog instead of trying the path I'd just typed in.
    >
    > If I use the file dialog to select the same directory, it then works.


    Just typing "c:\netbeans" at the prompt should have worked too,
    that's a bug. Sorry about that, will fix.

    Posted by: hansmuller on January 10, 2006 at 02:34 PM

  • Very cool. I tried it on my windows machine and it worked without a hitch. This is the way to go for open source projects, especially those hosted on java.net

    Posted by: inder on January 11, 2006 at 06:37 AM

  • Perhaps JmDNS would be an appropriate way to locate currently running instances of NetBeans.

    jmdns.sourceforge.net

    While this is very cool, I have somewhat mixed feelings about the direction of the implementation. By attempting to use an existing installation of NetBeans--time, bandwidth, and disk space are all saved. Along with those savings come a greatly increased probability that something won't work, since you are no longer using a known version of NetBeans or Java.

    Despite my quibbles, this rocks. I can't wait to see something like it find its way into the Java Trail examples.

    - Curt

    Posted by: coxcu on January 11, 2006 at 08:02 AM

  • That is cool idea. Are you planning to extend this to instal NetBeans first, if it is not available, before opening project/file?

    Posted by: vemulapallikishore on January 11, 2006 at 08:51 AM

  • It worked on my WinXP machine, cool.

    Posted by: fuerte on January 11, 2006 at 01:41 PM


  • > Posted by: vemulapallikishore on January 11, 2006 at 08:51 AM
    > ... Are you planning to extend this to instal NetBeans first, if it
    > is not available, before opening project/file?


    Installing NetBeans automatically was the original idea however
    it seemed like doing so would overwhelm the little helper
    application. Downloading something of that size would probably
    a much more sophisticated file transfer module than what I've
    written. Maybe someone has a bullet-proof file download
    class that handles errors and restarts and progress reporting?

    Posted by: hansmuller on January 11, 2006 at 02:27 PM


  • > Perhaps JmDNS would be an appropriate way to locate currently
    > running instances of NetBeans. jmdns.sourceforge.net


    Don't know anything about jmdns. This assume that NetBeans would
    register itself with an already-installed server at (IDE) startup
    time?


    > While this is very cool, I have somewhat mixed feelings about the
    > direction of the implementation. By attempting to use an existing
    > installation of NetBeans--time, bandwidth, and disk space are all
    > saved. Along with those savings come a greatly increased probability
    > that something won't work, since you are no longer using a known
    > version of NetBeans or Java.


    The Windows implementation does attempt to enumerate all of the
    installed versions of NetBeans with an eye towards allowing supporting
    an argument that specified which version was needed. I did not do as
    much for the Unix OS's, mostly because I wanted to finish. It seems
    like most Unix developers just drop the NetBeans distribution
    in a personally convenient place on the hard-drive, so (at the moment)
    finding installed copies automatically is often impossible.

    Posted by: hansmuller on January 11, 2006 at 02:34 PM

  • Thanks so much for this! This is exactly what I was looking for.
    ///////////////////////////FLV to AVI converterFLV to WMV
    FLV to MPEG
    FLV Converter
    SWF to FLV
    M4V converter
    Ipod to PC
    Ipod to PC transfer
    DVD to iPod AVI to SWF site has all solution on FLV to SWF,
    WMV to SWF, MPEG to SWF,
    3GP to SWF, DivX to SWF,AVI to FLV
    and other video to SWF, FLV ecoded by Java.
    May it Gadgets helpful To your lifestyle... Enjoy!!!

    Posted by: quinceseed on June 20, 2008 at 01:52 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds