Create 'native' Java applications on OS X and Windows using Maven plugins

When building a desktop application, the target audience usually expects an executable to when launching it. If the application is written in Java you have the options to create a batch file to launch it, create an executable jar file, compile the application as a native application or wrap the application using a native ‘launcher’. This post will result in a maven pom for dealing with the last option, it may be used in both Windows and OS X environments.

The pom is configured to use two different plugins depending on which operating system that is executing it.
On Windows, a Launch4j project plugin will be used. On OS X the osxappbundle plugin is used, which creates an OS X application directory structure and uses the JavaApplicationStub binary for launching the application.

The <profile> tag is used for deciding which plugin to use depending on operating system.

The pom also points out different application icons for the binaries, OS X requires the icon to be in the icns and windows in the ico format.

The wrapped application has a main class in the file com.jayway.wrappedapplication.Launcher

The pom.xml


  4.0.0
  com.jayway.wrappedapplication
  launcher
  jar
  1.0-SNAPSHOT
  launcher
  http://maven.apache.org
  
    
      windows-deploy
      
        
          Windows
        
      
      
        
          
            org.bluestemsoftware.open.maven.plugin
            launch4j-plugin
            1.5.0.0
            
              
                launch4j
                verify
                
                  launch4j
                
                
                  false
                  gui
                  ${project.build.directory}/relauncher-${project.version}.exe
                  ${project.build.directory}/${project.build.finalName}.jar
                  Launcher
                  
                    1.6.0
                  
                  
                    com.jayway.wrappedapplication.Launcher
                    false
                    anything
                  
                  ${basedir}/build-resources/win/icons/application.ico
                
              
            
          
        
      
    
    
      
        
          mac
        
      
      
        
          
            org.codehaus.mojo
            osxappbundle-maven-plugin
            1.0-alpha-2
            
              com.jayway.wrappedapplication.Launcher
              ${basedir}/build-resources/osx/icons/application.icns
            
            
              
                package
                
                  bundle
                
              
            
          
        
      
    
  

And that’s it.

This Post Has 2 Comments

  1. Thank you for pointing this out! This was very helpful for one of my projects.

  2. Just for the record: groupid and artifactid should have capitalized i’s in id, eg. artifactId

Leave a Reply

Close Menu