Adding another project bank as a resource using Maven

As part of my project, I have a subproject auto project. Basically a jar file that is extracted and run when an update is available.

Is it possible to compile the subproject, then place the output jar as generated-resourceto updater.jarbe included in the final jar, for example:

Project-1.0.jar
 |-updater.jar
    |-Main.class
    |-B.class

Thanks in advance for any help (I'm new to Maven)

+5
source share
3 answers

This task causes maven-assembly-plgineithermaven-dependency-plugin

(I expect updater is also a maven project), this shoudl will be the proper configuration for maven-dependency-plugin [I have not tested this, you may also need to install an update for the dependencies project]

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>company.com.project</groupId>
                  <artifactId>Updater</artifactId>
                  <version>0.0.1-SNAPSHOT</version>
                  <type>jar</type>
                  <outputDirectory>${project.build.outputDirectory}/classes</outputDirectory>
                  <destFileName>updater.jar</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
+3
source

, Maven. , POM :

<groupId>company.com.project</groupId>
<artifactId>Updater</artifactId>
<version>0.0.1-SNAPSHOT</version>

Project-1.0 :

<dependency>
    <groupId>company.com.project</groupId>
    <artifactId>Updater</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
0

Add the subproject to the parent project as follows

<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/maven-v4_0_0.xsd">

    <modelVersion>1.0.0</modelVersion>
    <groupId>Project-1.0</groupId>
    <artifactId>myproject</artifactId>
    <packaging>pom</packaging>

    <version>1.0-SNAPSHOT</version>

    <name>Project-1.0</name>

    <modules>
        <module>../updater</module>
    </modules>

    ...
</project>

Then, in the updater file of the updater project, make the following changes

<?xml version="1.0"?>
<project>
  <parent>
    <artifactId>myproject</artifactId>
    <groupId>Project-1.0</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>

  <groupId>Project-1.0</groupId>
  <artifactId>updater</artifactId>
  <version>1.0-SNAPSHOT</version>

  ...

</project>

When compiling the parent project, the child project will be automatically compiled.

Then, to add the jar of the subproject to your jar, add the following plugin to the parent pom.xml

 <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>process-resources</phase>
        <configuration>
          <tasks>
            <copy todir="${project.build.directory}/lib">
              <fileset dir="${location of updater1.0.jar}"/>
            </copy>
          </tasks>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
0
source

All Articles