maven 手动从本地导入jar包

发布时间 2023-07-20 23:45:13作者: 且行且思

Maven中的install命令生成的jar包在哪里

install命令生成的jar包一般在本地仓库中。

 

 

打包命令:

 

 

打包命令:3种把本地jar包添加到pom.xml的方式。
  • 1、 在本地maven仓库安装本地jar包
  • 2、把本地jar包放在项目的某个目录中
  • 3、使用scope system依赖

    1、 在本地maven仓库安装本地jar包

        maven install可以把指定的文件安装到本地maven仓库(使用maven指令前需要安装apache maven)。有三种install方式:

    (1)mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

    指定jar包、groupid、artifactId和version,maven会自动生成相应的pom.xml文件。

    (2)mvn install:install-file -Dfile=<path-to-file> -DpomFile=<path-to-pomfile>

    如果jar包是用maven打包生成的,可以直接指定jar包和pom.xml文件。

    (3)mvn install:install-file -Dfile=<path-to-file>

    如果jar包是用maven打包生成的,maven 2.5版本会自动根据jar包生成pom.xml文件。

 

 

(2)LocalJar打包:localjar-1.0.0.jar,在windows命令窗口输入mvn install指令:mvn install:install-file -Dfile=LocalJar.jar -DgroupId=nlp -DartifactId=localjar -Dversion=1.0.0 -Dpackaging=jar

具体安装的路径可以查看Installing给出的路径。

 

mvn install:install-file -DgroupId=com.supermap -DartifactId=com.supermap.data.conversion -Dversion=10.2.1-17815 -Dpackaging=jar -Dfile=\backend\\src\\main\\resources\\lib\\com.supermap.data.conversion.jar

mvn install:install-file -DgroupId=com.supermap -DartifactId=com.supermap.data -Dversion=10.2.1-17815 -Dpackaging=jar -Dfile=\backend\\src\\main\\resources\\lib\\com.supermap.data.jar

mvn install:install-file -DgroupId=com.supermap -DartifactId=com.supermap.mapping -Dversion=10.2.1-17815 -Dpackaging=jar -Dfile=\backend\\src\\main\\resources\\lib\\com.supermap.mapping.jar

mvn install:install-file -DgroupId=com.supermap -DartifactId=com.supermap.analyst.spatialanalyst -Dversion=10.2.1-17815 -Dpackaging=jar -Dfile=\backend\\src\\main\\resources\\lib\\com.supermap.analyst.spatialanalyst.jar

 

 

(3)LocalJarforMavenDemo项目的pom.xml添加localjar-1.0.0.jar包:

        <dependency>
            <groupId>nlp</groupId>
            <artifactId>localjar</artifactId>
            <version>1.0.0</version>
        </dependency>

 

3、使用scope system依赖

   和方法2类似,pom.xml添加dependency,但不需要添加。这种方法可能出现奇怪的错误,所以不推荐使用。这种引用,mave打包生成jar时,也未包含入;

<dependency>
            <groupId>nlp</groupId>
            <artifactId>localjar</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/repo/nlp/localjar/1.0.0/LocalJar.jar</systemPath>
        </dependency>