Package your desktop application

If you would like to deploy your DukeScript application for desktop, you can simply use maven:

>mvn -Pdesktop clean package

This works when the application has been created from the archetype. The pom.xml of your main project will then contain a profile like this:

<profile>
    <id>desktop</id>
    <dependencies>
        <dependency>
            <groupId>org.netbeans.html</groupId>
            <artifactId>net.java.html.boot.fx</artifactId>
            <version>${net.java.html.version}</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>${project.mainclass}</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <useUniqueVersions>false</useUniqueVersions>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>distro-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/javafx.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

The Maven assembly plugin is used to package everything. If you run the Maven command described above a ZIP-Archive will be created that you can deploy to your users. The application can then be started by a double-click on the main jar-file.

In the Plugin configuration section there’s a reference to the descriptor “javafx.xml”. You can modify this descriptor, if you want to add extra resources.

For example I recently needed to add a start script for Windows, because I wanted to pass the default encoding to the application. On Windows this is often CP1250 or CP1252, which can cause problems if users work on the same data files on different platforms. It’s easy to set the default encoding as a system property, but it has to happenbefore the application starts.

So the content my Batch File looks like this:

@ECHO OFF
javaw -Dfile.encoding=UTF8 -jar myapplication.jar

In the javafx.xml descriptor file find the filesets section. This is used to copy the HTML-Files, CSS, etc into the archive. It looks like this:

<fileSets>
    <fileSet>
       <directory>src/main/webapp/</directory>
       <outputDirectory>/</outputDirectory>
       <includes>
          <include>pages/**</include>
       </includes>
    </fileSet>
</fileSets>

Now copy this section and adjust it to your needs. My Batch-File is in the src/main/bin directory:

<fileSets>
    <fileSet>
       <directory>src/main/</directory>
       <outputDirectory>/</outputDirectory>
       <includes>
          <include>bin/**</include>
       </includes>
    </fileSet>
    <fileSet>
       <directory>src/main/webapp/</directory>
       <outputDirectory>/</outputDirectory>
       <includes>
          <include>pages/**</include>
       </includes>
    </fileSet>
  </fileSets>

That’s it. If you package the application the next time this File will also be copied.

By the way: If you’re using NetBeans there’s a convenient predefined action in the context menu of your project: “Run Maven” -> “Build Desktop app” which starts the Maven command described above.