0

I am trying to use maven to assemble a directory for a install package. The install package requires several things: configuration files, dependency libraries and an executable jar of my class files. I am having trouble figuring out how to add the executable jar.

Here is what I have so far:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myproject</groupId>
  <artifactId>myproject</artifactId>
  <version>8.1.1</version>
  <name>my project</name>
  <packaging>pom</packaging>
  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>


        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-2</version>
            <configuration>
                <descriptor>${basedir}/src/main/assembly/client.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <id>create-client</id>
                    <configuration>
                        <descriptor>${basedir}/src/main/assembly/client.xml</descriptor>
                    </configuration>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>

  <dependencies>
      .
      .
      .
  </dependencies>
</project>

Then my assembly descriptor looks like this:

<assembly>
  <id>client</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>

  <fileSets>
    <fileSet>
        <directory>${basedir}/src/main/reports</directory>
        <outputDirectory>/reports</outputDirectory>
    </fileSet>
    <fileSet>
        <directory>${basedir}/src/main/resources/audio</directory>
        <outputDirectory>/audio</outputDirectory>
    </fileSet>
    <fileSet>
        <directory>${basedir}/src/main/client</directory>
        <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
        <scope>runtime</scope>
        <useProjectArtifact>false</useProjectArtifact>
        <outputDirectory>lib</outputDirectory>
        <unpack>false</unpack>
    </dependencySet>
  </dependencySets>
</assembly>

If i call mvn assembly:assembly I get a directory with all the libraries and configuration files. Works great.

But now I want to add an executable jar of all my compiled code. I can create this jar alone by adding this to my pom and calling mvn jar:jar

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <finalName>run</finalName>
                <archive>
                    <manifest>
                        <mainClass>com.myproject.main.StartProcess</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

The question is, how can I get that jar into my assembly automatically? I have tried a couple things but I have no idea where to start. Can I somehow call the jar execution from my assembly?

Any help appreciated.

potame
  • 7,597
  • 4
  • 26
  • 33
springcorn
  • 611
  • 2
  • 15
  • 28
  • I think having a look at this link would be helpful http://stackoverflow.com/questions/1814526/problem-building-executable-jar-with-maven – Roveris May 18 '13 at 22:09

1 Answers1

1

I think you should turn your useProjectArtifact to true (this is the default value).
It determines whether the artifact produced during the current project's build should be included in this dependency set.

webpat
  • 1,889
  • 16
  • 21