NetBeans 5.5.1 and later contain functionality that allows you to easily share code samples and NetBeans projects over the internet. Just create a ZIP file of your project or projects and make it available from anywhere on the web, then create a URL with the parameters listed below. A Java WebStart application will launch that looks for a suitable build of NetBeans on the user's machine, opens the IDE, extracts the project to where? , and opens the projects in the IDE. You can use this for your blog entries, tutorials, or anything else. It's like the YouTube of Java sample code!
The IDE uses the command line interface (CLI) of NetBeans launcher to open projects from the web. The CLI of the launcher can be used to open a project from command line. The command looks like this:
netbeans --open [list nb project dirs separated by space, last project is opened as main]
The CLI is used by the WebStart application that downloads projects from web and then opens them in the IDE.
You can open one project or several at one time, for example some suite of projects like an enterprise application or a desktop app and its library projects. To open several projects at once, all projects must be zipped to one zip file. Projects can be also nested inside other projects. Projects must be archived without the nbproject/private folder, as this folder contains files with absolute paths and other non-sharable data. For creating the zip file you can use the ProjectPackager module from contrib.netbeans.org. If you are going to zip projects by hand, the best way is to copy them all to some folder (make sure you don't break dependencies by copying them), delete 'nbproject/private' folder from all projects and then zip them up. Project folders should be the top-level folders in the zip file (except for nested subprojects, as in Java EE applications).
When the zip archive is ready, it must be placed on an HTTP server accessible from the internet so that you have the public URL of the zip file. There are three parameters that can be passed to the application via the URL:
Note that the open project functionality is available from NetBeans version 5.5.1 which is also the fallback version if no version is specified in the URL.
Setup the URL as the following:
http://www.netbeans.info/services/openproject.jnlp?projecturl=[URL of the zip file with projects]&minversion=[minimum version of NetBeans]
If any project is supposed to be opened as main project you need to add one more parameter to the URL:
mainproject=[Path of the main project in the zip file, use '/' as separator]
Final URL might look like this:
http://www.netbeans.info/services/openproject.jnlp?projecturl=http://mysite.org/projects.zip&minversion=5.5.1&mainproject=TheMainProject
The application logs all its actions to a log file called projectopener.log in the temp dir. For Unix platforms it's usually /tmp folder, for windows it's usually C:\Documents and Settings\{username}\Local Settings\Temp (or its localized equivalents).
Opening project from URL is based on Java Web Start technology. When a user clicks the link, a new JNLP file is generated with the parameters passed from the URL translated to arguments for the application. The JNLP client on the user's computer downloads the JAR file of the application specified in the JNLP file and executes its main class. The main class processes the passed arguments and if everything is OK it starts to download the project ZIP file. If the download is successful, it starts looking for the proper NetBeans IDE installation by searching the .netbeans folder in the user's home dir. If a correct installation is found, then the IDE is started and the project folders are passed to it. There might be lots of unexpected situations, e.g. wrong parameters, bad proxy settings, failed download, no NetBeans IDE installation found, etc. - all these situations are handled by error messages or dialogs. If the application encounters an unrecoverable problem, the application is terminated.
To try out the opening of project in NetBeans IDE, you can click the following link. It will open dummy project which can be immediately executed by pressing F6:
| CopyFQN.zip | ![]() |
7251 bytes |