user3742622
user3742622

Reputation: 1067

Maven: How to install my jar to local repo after building

I want to build a package and install it to my local repo. My pom file is:

<?xml version="1.0" encoding="UTF-8"?>
<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.me</groupId>
    <artifactId>MyApp</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <!-- This block declare a dependencies for this project -->
    <dependencies>

        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>

    <build>

        <!-- This block declare a plugins -->
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
            </plugin>

<!-- Installing to local repo -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
                <configuration>
                    <groupId>com.me</groupId>
                    <artifactId>MyApp</artifactId>
                    <version>1.0.0</version>
                    <packaging>jar</packaging>
                    <file>/Users/me/MyApp/target/MyApp-1.0.0.jar</file>
                    <generatePom>true</generatePom>
                </configuration>
                <executions>
                    <execution>
                        <id>install-jar-lib</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>validate</phase>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

But when I run "mvn package" comand I get a error that there is no file: /Users/me/MyApp/target/MyApp-1.0.0.jar So I comment install plugin, run "mvn package", uncoment install plugin and run "mvn package". Could I do this thing in one step? Without this comment-uncomment thing?

Upvotes: 1

Views: 2791

Answers (2)

Adrian Duta
Adrian Duta

Reputation: 81

from what i know, mvn clean install, put the package in the local repo, without any need of any plugin

Upvotes: 0

Tunaki
Tunaki

Reputation: 137084

It's not clear why you need to invoke the install-file goal of maven-install-plugin but the problem lies in the phase. You configured it with <phase>validate</phase> when it should be <phase>package</phase> instead.

Take a look at the Introduction to the Build Lifecycle: phase validate is the first phase that is executed by Maven. At this time, the jar was not built so it can't work.

If you really want the artifact to be installed on the package phase (when running mvn package) then the phase should be set to package.

Note that instead of running mvn package, you should just call mvn install without the need of configuring the maven-install-plugin. The artifact will be automatically installed in your local repo with this command.

Upvotes: 5

Related Questions