maven 将jar包添加本地仓库源
有如下jar包
zxing3.2.1.jar
zxingcore.jar
QRCode.jar
存在于本机目录
D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\ 下:
安装maven (此处已安装,省略),将maven添加环境变量
执行
mvn install:install-file -DgroupId=com.swetake.util.Qrcode -DartifactId=QRcode -Dversion=1.0.0 -Dpackaging=jar -Dfile="D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\QRCode.jar"
命令解释:
-DgroupId :对应pom.xml 文件中的 groupId
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>QRcode</artifactId>
<version>3.2.1</version>
</dependency>
-DartifactId 对应pom.xml文件中的 artifactId
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>QRcode</artifactId>
<version>3.2.1</version>
</dependency>
-Dversion :jar 版本。
-Dfile :本机jar包物理路径,路径中如有空格请使用双引号处理此路径。
查看mvn帮助
C:\Users\nantian>mvn --help usage: mvn [options] [<goal(s)>] [<phase(s)>] Options: -am,--also-make If project list is specified, also build projects required by the list -amd,--also-make-dependents If project list is specified, also build projects that depend on projects on the list -B,--batch-mode Run in non-interactive (batch) mode (disables output color) -b,--builder <arg> The id of the build strategy to use -C,--strict-checksums Fail the build if checksums don't match -c,--lax-checksums Warn if checksums don't match -cpu,--check-plugin-updates Ineffective, only kept for backward compatibility -D,--define <arg> Define a system property -e,--errors Produce execution error messages -emp,--encrypt-master-password <arg> Encrypt master security password -ep,--encrypt-password <arg> Encrypt server password -f,--file <arg> Force the use of an alternate POM file (or directory with pom.xml) -fae,--fail-at-end Only fail the build afterwards; allow all non-impacted builds to continue -ff,--fail-fast Stop at first failure in reactorized builds -fn,--fail-never NEVER fail the build, regardless of project result -gs,--global-settings <arg> Alternate path for the gl
...........
更多详情参考
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html
运行cmd 执行操作如下:
C:\Users\nantian>mvn install:install-file -DgroupId=com.swetake.util.Qrcode -DartifactId=QRcode -Dversion=1.0.0 -Dpackaging=jar -Dfile="D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\QRCode.jar" [INFO] Scanning for projects... [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom --- [INFO] Installing D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\QRCode.jar to C:\Users\nantian\.m2\repository\com\swetake\util\Qrcode\QRcode\1.0.0\QRcode-1.0.0.jar [INFO] Installing C:\Users\nantian\AppData\Local\Temp\mvninstall7496630837639804466.pom to C:\Users\nantian\.m2\repository\com\swetake\util\Qrcode\QRcode\1.0.0\QRcode-1.0.0.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.462 s [INFO] Finished at: 2018-11-06T15:01:40+08:00 [INFO] ------------------------------------------------------------------------ C:\Users\nantian>mvn install:install-file -DgroupId=com.google.zxing -DartifactId=QRcode -Dversion=3.2.1 -Dpackaging=jar -Dfile="D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\zxing3.2.1.jar" [INFO] Scanning for projects... [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom --- [INFO] Installing D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\zxing3.2.1.jar to C:\Users\nantian\.m2\repository\com\google\zxing\QRcode\3.2.1\QRcode-3.2.1.jar [INFO] Installing C:\Users\nantian\AppData\Local\Temp\mvninstall3882659277016851967.pom to C:\Users\nantian\.m2\repository\com\google\zxing\QRcode\3.2.1\QRcode-3.2.1.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.980 s [INFO] Finished at: 2018-11-06T15:12:29+08:00 [INFO] ------------------------------------------------------------------------ C:\Users\nantian>mvn install:install-file -DgroupId=com.google.zxing -DartifactId=zxing -Dversion=1.7.0 -Dpackaging=jar -Dfile="D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\zxingcore.jar" [INFO] Scanning for projects... [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom --- [INFO] Installing D:\Program Files\eclipse_workspace\webapp\WebContent\WEB-INF\lib\zxingcore.jar to C:\Users\nantian\.m2\repository\com\google\zxing\zxing\1.7.0\zxing-1.7.0.jar [INFO] Installing C:\Users\nantian\AppData\Local\Temp\mvninstall3510646588980436125.pom to C:\Users\nantian\.m2\repository\com\google\zxing\zxing\1.7.0\zxing-1.7.0.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.587 s [INFO] Finished at: 2018-11-06T15:14:24+08:00 [INFO] ------------------------------------------------------------------------ C:\Users\nantian>
进入IntelliJ IDEA中配置项目pom.xml 文件
<dependency> <groupId>com.swetake.util.Qrcode</groupId> <artifactId>QRcode</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.google.zxing</groupId> <artifactId>QRcode</artifactId> <version>3.2.1</version> </dependency> <dependency> <groupId>com.google.zxing</groupId> <artifactId>zxing</artifactId> <version>1.7.0</version> </dependency>
选择右下角的import Changes 。