在涉及maven时jar包自动导不上去解决方法

有些时候我们需要在项目中导入一些依赖包,这些包可能在maven中央库中没有,这时候我们就需要手动导入本地库,让maven能够检索到。

为此我们先要配置maven环境变量:将maven的bin目录路径:E:\apache-maven-3.2.1\bin 添加到classpath中。
然后创建执行文件:

首先新建一个txt文件,在里面写入我们希望执行的命令,比如我要导入这个包
那这里的命令为:

mvn install:install-file -Dfile=./utils-core-1.0.3.jar -DgroupId=com.obanks -DartifactId=utils-core -Dversion=1.0.3 -Dpackaging=jar

然后将后缀名改为.bat,变成可执行文件:

最后双击该文件执行命令,这样我们就将jar包导入本地库。
另外当在项目中导不进来时可以:
maven 构建项目时,可能会引用到一些公司的其他项目。或引用的jar 包在maven 主仓库加载不到。
这时我们可以将我们需要的jar 包安装到本地仓库中。方法如下。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.1.0.RELEASE</version>
</dependency>

Maven 安装 JAR 包的命令是:
mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面的version -Dpackaging=jar
例如:
我下载的这个 jar 包是放到了 D:\mvn 目录下(D:\mvn\spring-context-support-3.1.0.RELEASE.jar)
那么我在 cmd 中敲入的命令就应该是:

mvn install:install-file -Dfile=D:\mvn\spring-context-support-3.1.0.RELEASE.jar -DgroupId=org.springframework -DartifactId=spring-context-support-Dversion=3.1.0.RELEASE -Dpackaging=jar

当然也可以直接加入到项目中:

<dependency>
           <groupId>struts</groupId>
            <artifactId>struts</artifactId>
            <version>1.3.10</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/javabuilder.jar</systemPath>
</dependency>

ps:此种方式使用maven打包时,不会将scope为system的jar打入到部署包中。

猜你喜欢

转载自blog.csdn.net/ligh_sqh/article/details/79498089
今日推荐