Question

End goal is I am trying to build an executable jar in eclipse with maven, that's packaged with its dependencies like so. The end file structure I'm trying to accomplish is the following..

/target/my-distributable.zip
        |- lib (all third party jar's, which I have loaded through maven)
        |- images (the images my swing app can reference)
        |- my-application.jar (my executable jar, manifiest within with correct classpath references)
        |- my-application.properties (the properties my app reads and can modify)
        |- READ-ME.TXT

From here the end user would be able to unzip the distributable zip file, double click on the jar to start a java swing application which has dependencies located in the /lib directory. And there's a text editor in/as part of the swing app that I'd like to have reference images from the /images directory. What I would like to accomplish is having maven create a zip file which contains everything in this /dist folder, including my executable jar and it's dependencies located in a lib directory.

I know I need to have my exec jar's manifest include the Main class from which to run the application, and include the lib and images directory on the classpath of the manifest as well as my properties file.

I have tried several combinations of the maven shade plugin which seems to throw everything in one jar (not useful here as I need the zip with my exec jar inside, and lib outside the exec jar), and maven-assembly-plugin.

Here is my current POM with dependencies..

<project 
    xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.kiosk</groupId>
  <artifactId>kiosk-application</artifactId>
  <version>2.1</version>

  <name>Kiosk Application</name>

    <properties>
        <jdk.version>1.5</jdk.version>
    </properties>

  <dependencies>

    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.1</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.10</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>

    <dependency>
        <groupId>commons-jxpath</groupId>
        <artifactId>commons-jxpath</artifactId>
        <version>1.3</version>
    </dependency>

    <dependency>
        <groupId>net.sf.ezmorph</groupId>
        <artifactId>ezmorph</artifactId>
        <version>1.0.6</version>
    </dependency>

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.5.0</version>
    </dependency>

    <dependency>
        <groupId>com.miglayout</groupId>
        <artifactId>miglayout</artifactId>
        <version>3.7.4</version>
    </dependency>

    <dependency>
        <groupId>com.shef</groupId>
        <artifactId>shef</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>net.sf.json-lib</groupId>
        <artifactId>json-lib</artifactId>
        <version>2.2.2</version>
    </dependency>

    <dependency>
        <groupId>com.novaworx.syntax</groupId>
        <artifactId>novaworx-syntax</artifactId>
        <version>0.0.7</version>
    </dependency>

    <dependency>
        <groupId>sam.i.am</groupId>
        <artifactId>sam-i-am</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>jtidy.me</groupId>
        <artifactId>jtidy-8</artifactId>
        <version>8.0</version>
    </dependency>

  </dependencies>
</project>

And this is my last attempt with using the maven-assembly-plugin adding to the pom above..

  <build>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <versionRange>[2.0,)</versionRange>
                    <goals>
                      <goal>copy-dependencies</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute />
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                  <source>1.5</source>
                  <target>1.5</target>
                </configuration>
            </plugin>

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/libs</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <compress>true</compress>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>libs/</classpathPrefix>
                            <mainClass>com.kiosk.app.KioskApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>



           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>/src/main/assembly/assembly.xml</descriptor>
                    </descriptors>
                    <finalName>kiosk-application_${project.version}</finalName>
                    <outputDirectory>${project.build.directory}/dist</outputDirectory>
                    <workDirectory>${project.build.directory}/assembly/work</workDirectory>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

    </plugins>

  </build>

And my

assembly.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>bundle</id>
    <formats>
        <format>jar</format>
    </formats>
    <filesets>
        <fileset>
            <directory>target</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileset>
        <fileset>
            <directory>target/libs</directory>
            <outputDirectory>libs</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileset>
    </filesets>
</assembly>

My application structure..

/src
 |- main
    |- assembly
    |- java
       |- com
          |- kiosk
             |- etc....
    |- resources
       |- myImage.jpg
       |- my-application.properties

When I try to use the pom above with the build section using the maven-assembly-plugin I'm currently getting the error..

Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2.1:single (default) on project kiosk-application: Error reading assemblies: Error reading descriptor: /src/main/assembly/assembly.xml: Unrecognised tag: 'filesets' (position: START_TAG seen ...\r\n ... @8:15) -> [Help 1]

This seems like what should be a fairly easy task to accomplish, however I have never used maven to accomplish this sort of thing and I'm having an issue orchestrating the build to produce the end result I'd like to accomplish. Is there any maven experts out there than can help point me in the right direction..?

Was it helpful?

Solution

You should be using fileSets instead of filesets in your assembly.xml. Note uppercase 'S' letter. The same applies to several other XML tags.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top