Desklets 102: Dependencies

by Robert Cooper

Josh held the premiere session for AB5k Tue at Java Posse Roundup (I will post a summary of the week soon). Since there is some discussion going on, including our getting panned at JavaLobby, I thought I would write up a little bit about how the desklet runner system works.

.desklet files are, simply, JAR files. Inside the META-INF folder you place a desklet.xml file that looks something like this:

<br />
<?xml version="1.0" encoding="UTF-8"?><br />
<desklet version="0.1"><br />
    <name>ROME Reader</name><br />
    <author>Robert Cooper</author><br />
    <homepage>http://www.screaming-penguin.com</homepage><br />
    <description>An RSS/Atom Feed Reader</description><br />
    <class>com.totsp.desklet.rome.RomeDesklet</class><br />
    <repository>http://myserver/repo</repository><br />
    <dependency><br />
        <groupId>jtidy</groupId><br />
        <artifactId>jtidy</artifactId><br />
        <version>8.0-20060801.131059-3</version><br />
    </dependency><br />
    <dependency><br />
        <groupId>rome</groupId><br />
        <artifactId>rome</artifactId><br />
        <version>0.9</version><br />
    </dependency><br />
    <dependency><br />
        <groupId>jdom</groupId><br />
        <artifactId>jdom</artifactId><br />
        <version>1.0</version><br />
    </dependency><br />
    <dependency><br />
        <groupId>FlyingSaucer</groupId><br />
        <artifactId>core-renderer</artifactId><br />
        <version>R6</version><br />
    </dependency><br />
    <dependency><br />
        <groupId>FlyingSaucer</groupId><br />
        <artifactId>cssparser</artifactId><br />
        <version>0.9.4</version><br />
    </dependency><br />
</desklet><br />


Most of the stuff at the top is pretty straightforward. The big thing here is the dependency management. There are a number of ways you can specify deps for your desklet. The recommended way is to specify them in the desklet file, alternately specifying a repository in Maven 1 layout (M2 will be supported soon), and declare the dependencies in your desklet.xml file. When your desklet is installed the required dependencies will be downloaded and put into a shared repository. The reason this is the best tact is downloaded dependencies are put into a shared repository and are not re-downloaded for each desklet, improving the user experience, and reducing desklet size.

Another option is to place the dependencies in the META-INF/lib folder in a Maven 1 repository directory structure. That is, META-INF/lib/[groupId]/jars/[artifactId]-[version].jar. Jars packaged in this manner will take precedent over the local repository. This can be useful if you want to ensure for security or other reasons that the exact version of the Jar you want will be used with your desklet.

The final way you can package dependencies is to simply place Jars you need into the META-INF/lib folder directly. These jars will be in place for your desklet, but do not have to be declared in the desklet file. This is a convenience, and can be useful if you have Jars that are not deployed to a Maven repository. However, please keep in mind your desklet files can become large when you do this.

That is all for now. You can expect Josh to be posting information on the specifics of writing desklets this weekend. I will also post information about security and runtime of desklets later this weekend. Also, please keep in mind that between now and JavaOne a lot is expected to change.