日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

maven依赖包快速下载

發布時間:2024/8/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 maven依赖包快速下载 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在離線環境進行maven項目開發時,總會遇到需要頻繁添加jar包依賴來進行功能拓展,然而某一個jar包的引入,又會需要間接依賴很多其他的類庫,一個一個地下載又很麻煩。當然你也可以在外網搭建一套同樣的開發環境,通過開發工具自動下載,再把外網本地倉庫拷貝到內外環境。這里記錄一種稍微簡單點的方法:

1、前提:外網安裝了maven以及配套java,并配置maven以及java環境變量;

2、隨便找一個位置創建文件夾,在該文件夾下創建一個pom.xml文件:

<?xml version="1.0"?> <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>download</groupId><artifactId>download</artifactId><version>1.0.0</version><dependencies><dependency><groupId>xxx</groupId><artifactId>xxx</artifactId><version>xxx</version></dependency></dependencies> </project>

自己把需要下載的依賴補充完整。

3、當前目錄下運行:

mvn -f pom.xml dependency:copy-dependencies

執行完成后,當前目錄下會多出一個target文件夾,里頭是下載的直接或間接依賴包,在maven倉庫下會有完整的.jar和.pom,全部拷貝就好了。

4、maven默認本地倉庫為C:\Users\你的賬戶\.m2\repository;

可以自己改maven的相關配置,配置文件在maven安裝目錄下 /conf/settings.xml,設置本地倉庫位置以及國內下載鏡像源:

<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"><localRepository>D:\ide\maven\localRepository</localRepository><interactiveMode>true</interactiveMode><offline>false</offline><pluginGroups><pluginGroup>org.apache.maven.plugins</pluginGroup><pluginGroup>org.codehaus.mojo</pluginGroup></pluginGroups><proxies><!--<proxy><id></id><active>true</active><protocol>http</protocol><username></username><password></password><host></host><port></port><nonProxyHosts></nonProxyHosts></proxy>--></proxies><servers><!--<server><id></id><username></username><password></password></server>--><!--<server><id>siteServer</id><privateKey>/path/to/private/key</privateKey><passphrase>optional; leave empty if not used.</passphrase></server>--></servers><mirrors><mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror></mirrors><profiles></profiles><activeProfiles></activeProfiles> </settings>

5、我自己把外網的repository全部復制到內網之后,出現了maven庫不能用的問題,主要是repository里的_remote.repositories和*.lastUpdated文件導致的,需要刪除:

public class Test {public static void main(String[] args) {File file = new File("D:\\ide\\maven\\localRepository");delete(file);}private static void delete(File file) {if(file == null) {return;}if(file.isDirectory()) {File[] files = file.listFiles();if(files != null) {for(File childFile : files) {delete(childFile);}}} else {if(file.getName().equals("_remote.repositories") || file.getName().endsWith(".lastUpdated")) {file.delete();}}} }

總結

以上是生活随笔為你收集整理的maven依赖包快速下载的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。