Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding another project's jar as a resource using Maven

Tags:

java

maven

Within my project I have a sub-project auto-updater. Basically a jar file that is extracted and run when an update is available.

Is it possible to compile the sub-project, then place the outputted jar as a generated-resource so that the updater.jar is included in the final jar such as:

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

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

like image 409
Opal Avatar asked Mar 20 '13 13:03

Opal


People also ask

How do I add a project as a dependency of another project in Maven?

Right-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.

Can we add external jar in Maven project?

Approach 2: Include jar as part of the maven project. In this approach you need to first create a folder in your maven project & add your external jar file. Once the jar file is added, include the jar file in your pom using following notation.


1 Answers

This task is calling for maven-assembly-plgin or maven-dependency-plugin

(I expect that updater is also maven project) this shoudl be proper configuration for maven-dependency-plugin [I did not test this, you might also need to put updater to project depndencies]

<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>
like image 103
Hurda Avatar answered Nov 06 '22 10:11

Hurda