簡體   English   中英

Maven:構建后如何將我的jar安裝到本地倉庫

[英]Maven: How to install my jar to local repo after building

我想構建一個軟件包並將其安裝到我的本地倉庫中。 我的pom文件是:

<?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>

但是,當我運行“ mvn軟件包” comand時,我得到一個錯誤,即沒有文件:/Users/me/MyApp/target/MyApp-1.0.0.jar所以我評論安裝插件,運行“ mvn軟件包”,沒有安裝插件並運行“ mvn軟件包”。 我可以一步一步做這件事嗎? 沒有這個注釋不注釋的東西?

目前尚不清楚為什么需要調用maven-install-plugininstall-file目標,但問題出在該階段。 您應將其配置為<phase>package</phase>時使用<phase>validate</phase>對其進行配置。

看一下構建生命周期簡介 :階段validate是Maven執行的第一階段。 目前,此Jar尚未構建,因此無法正常工作。

如果您確實希望將工件安裝在package階段(運行mvn package ),則應將該階段設置為package

注意,除了運行mvn package ,您應該只調用mvn install而不需要配置maven-install-plugin 使用此命令,工件將自動安裝在本地倉庫中。

據我所知,MVN全新安裝,將軟件包放在本地倉庫中,不需要任何插件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM