13

I am trying to integrate the generation of an installer as part of a maven compilation process.

I have found Alakai's plugin for Launch4j. I have create a simple Hello World application using Maven. I have tried to use configuration examples provided by Alakai, but when I compile my project, I get:

Failed to execute goal org.bluestemsoftware.open.maven.plugin:launch4j-plugin:1.5.0.0:launch4j (launch4j) on project Launch4j: Failed to build the executable; please verify your configuration. Application jar doesnt exist. -> [Help 1]

Unfortunately, Alakai's documentation is limited and I could not find much with Googling.

  • Does anyone know where the Launch4j config.xml should be set? Is it within the project? Is it in a separate directory?
  • Do I need to use the assembly plugin?
  • I have installed Launch4j on my PC. Do I need to specify the installation directory in my pom.xml? If yes how?
  • Does anyone have an operational pom.xml sample/example to share?

Thanks.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • 1
    just a relevant information: The answers for this question also applies to the 9 St. Mary Rd. launch4j plugin, which is the original one (AFAIK). If your using this old version, I recommend you to migrate to Alakai's last version. – Bruno Medeiros Jun 02 '11 at 13:12

2 Answers2

27
  1. There's no config.xml, you need to configure launch4j inside your pom.xml file.
  2. You could use maven-assembly-plugin, but I recommend you to use maven-shade-plugin.
  3. Don't need to specify launch4j installation, this plugin works 100% maven.
  4. Sure. Follows the shade and launch4j configs I use, that generates two exes, one console and one gui, using different main classes:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <shadedArtifactAttached>true</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
        <shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
    </configuration>
</plugin>

<plugin>
    <groupId>org.bluestemsoftware.open.maven.plugin</groupId>
    <artifactId>launch4j-plugin</artifactId>
    <version>1.5.0.0</version>
    <executions>

        <!-- GUI exe -->
        <execution>
            <id>l4j-gui</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>gui</headerType>
                <outfile>target/app-gui.exe</outfile>
                <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above -->
                <errTitle>App Err</errTitle>
                <classPath>
                    <mainClass>package.AppGUI</mainClass>
                </classPath>
                <icon>src/main/resources/icons/exeIcon.ico</icon>
                <jre>
                    <minVersion>1.5.0</minVersion>
                    <maxVersion>1.6.0</maxVersion>
                    <initialHeapSize>128</initialHeapSize>
                    <maxHeapSize>1024</maxHeapSize>
                </jre>
                <versionInfo>
                    <fileVersion>1.0.0.0</fileVersion>
                    <txtFileVersion>1.0.0.0</txtFileVersion>
                    <fileDescription>Desc</fileDescription>
                    <copyright>C</copyright>
                    <productVersion>1.0.0.0</productVersion>
                    <txtProductVersion>1.0.0.0</txtProductVersion>
                    <productName>Product</productName>
                    <internalName>Product</internalName>
                    <originalFilename>App.exe</originalFilename>
                </versionInfo>
            </configuration>
        </execution>

        <!-- Command-line exe -->
        <execution>
            <id>l4j-cli</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>console</headerType>
                <outfile>target/app-cli.exe</outfile>
                <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above -->
                <errTitle>App Err</errTitle>
                <classPath>
                    <mainClass>package.AppCLI</mainClass>
                </classPath>
                <icon>src/main/resources/icons/exeIcon.ico</icon>
                <jre>
                    <minVersion>1.5.0</minVersion>
                    <maxVersion>1.6.0</maxVersion>
                    <initialHeapSize>128</initialHeapSize>
                    <maxHeapSize>1024</maxHeapSize>
                </jre>
            </configuration>
        </execution>
    </executions>
</plugin>

Alternatively, You can omit the 'jar' tag on launch4j-plugin and remove the extra configs of the shade-plugin, but be aware that this will replace the main jar of the flow (without embedded dependencies) by the shaded jar (with embedded dependencies), and this one will be installed on your local repo, or used in the reactor if needed.

Bruno Medeiros
  • 2,251
  • 21
  • 34
  • 1
    Fantastic, it works. But, I found a small twist in your example. maven-shade-plugin does not seem to keep the main class name in the manifest. So, when I double click on the exe, I get a class not found. I used the assembly plugin instead (a devil I know). – Jérôme Verstrynge Jun 01 '11 at 02:04
  • AFAIK, we don't need the main class on manifest to make it work. Have you doouble checked the fully qualified class name? I just took it from a already-in-production project, just changed the names. If you want to send me your pom, I can help you, my email is my nickname, at gmail. Anyway, great you could solve your problem! – Bruno Medeiros Jun 02 '11 at 13:07
  • Thanks for the offering. I could set the main class in the assembly plugin. It is all clean now. – Jérôme Verstrynge Jun 03 '11 at 03:40
  • 2
    A newer and better version of the plugin is available here: https://github.com/vorburger/launch4j-maven-plugin – Bruno Medeiros May 21 '12 at 19:40
  • Can someone provide an example (snip) on how to use the assembly-plugin? – Ich Mar 30 '13 at 12:28
  • Wild - it's failing on the icon - if I comment out the icon, it works great. – Kieveli Aug 19 '13 at 12:27
  • The icon must be in a specific ico format, but I don't remember details now. I think it's defined on launch4j docs. – Bruno Medeiros Feb 07 '14 at 16:43
  • When running mvn install or release the created executables are not copied to the repository! https://stackoverflow.com/q/25996189/2764459 – VeikkoW Sep 29 '14 at 07:07
  • VeikkoW, have you tried to keep the executable as the main artifact? – Bruno Medeiros Dec 08 '14 at 19:00
  • the version 1.5.0 does not work on Mac OS X - for current version i am using now version 1.7.5 which works great! find it at http://search.maven.org/#artifactdetails%7Ccom.akathist.maven.plugins.launch4j%7Claunch4j-maven-plugin%7C1.7.5%7Cmaven-plugin – Sevyls Apr 04 '15 at 21:35
  • Why do I get an error while have set the fileVersion to '1.0.0.0'? – Arthur Eirich Sep 18 '15 at 15:59
  • I don't know, Arthur. Are you able to make it work with another version number? – Bruno Medeiros Oct 27 '15 at 11:40
1

For how to define the main class for the shade plugin, see http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html.

Jon Onstott
  • 13,499
  • 16
  • 80
  • 133