Wednesday, February 29, 2012

Deploying Swing applications on Linux with Maven and RPM

In the final part of application deployment series, I'll cover how to deploy Swing application as an RPM package. For this purpose, I'll use Maven RPM plugin to integrate deployment with application build process. Note that rpm tool must be installed on a system in order for this to work.

We start with simple Maven project as usual, and then configure Maven RPM plugin to run during package phase. Plugin configuration is shown in code snippet bellow:



<build>
      <plugins>
          <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>rpm-maven-plugin</artifactId>
              <version>2.0.1</version>
              <executions>
                  <execution>
                      <phase>install</phase>
                      <goals>
                          <goal>rpm</goal>
                      </goals>
                  </execution>
              </executions>
              <configuration>
                  <copyright>GPL</copyright>
                  <group>Applications</group>
                  <mappings>
                      <mapping>
                          <directory>/usr/local/${project.artifactId}</directory>
                          <filemode>0755</filemode>
                          <sources>
                              <source>
                                  <location>${project.build.directory}/maven-rpm-1.0-SNAPSHOT.jar</location>
                              </source>
                              <source>
                                <location>${project.build.outputDirectory}/myapp.sh</location>
                            </source>
                            <source>
                                <location>${project.build.outputDirectory}/myapp.png</location>
                            </source>
                          </sources>
                      </mapping>
                      <mapping>
                        <directory>/usr/share/applications</directory>
                        <sources>
                            <source>
                                <location>${project.build.outputDirectory}/myapp.desktop</location>
                            </source>
                        </sources>
                      </mapping>
                  </mappings>
                  <requires>
                      <require>java-1.7.0-openjdk</require>
                  </requires>
              </configuration>
          </plugin>
      </plugins>
  </build>

In the first part of configuration, we set the plugin to run rpm goal during install phase. We also set copyright and group information, which are mandatory. Copyright refers to application license, and  group to software group it should belong to.

File mapping is the most important part. In each mapping element, we set target directory for installation, and application files that should go in it. You can check out project source code attached to this post to see what each file does. In short:
  • myapp.sh - a shell script to execute the application
  • myapp.png - application icon
  • myapp.desktop - application desktop file
Final part of configuration lists package dependencies. We set it to require Java 7. Please note that this package name is valid for Fedora, while on other distributions it can be different. This should be taken into account when configuring dependencies.

The image bellow shows Fedora start menu with our application installed,
Start menu with application installed

Source code for this project can be found here 
You can also check out previous posts from this series:

No comments:

Post a Comment