怎樣做到節(jié)能減排 如何做到節(jié)能減排
2024-07-02
更新時(shí)間:2024-07-02 18:02:43作者:未知
準(zhǔn)備工作使用前請(qǐng)確保您已安裝JDK及Maven。如果您尚未安裝,可以點(diǎn)擊下面鏈接下載安裝:JDK官網(wǎng)下載地址:
https://www.oracle.com/technetwork/java/javase/downloads/index.htmlMaven加速地址:https://repo.huaweicloud.com/apache/maven/maven-3/
使用說明點(diǎn)擊此處 下載settings.xml文件,覆蓋<Maven安裝目錄>/conf/settings.xml文件即可。如果您不想覆蓋配置文件,可以手動(dòng)在settings.xml文件中的mirrors節(jié)點(diǎn)中添加如下內(nèi)容:
<mirror> <id>huaweicloud</id> <mirrorOf>*</mirrorOf> <url>https://repo.huaweicloud.com/repository/maven/</url></mirror>
相關(guān)網(wǎng)址Maven官方地址:
https://maven.apache.orgMaven搜索地址:http://mvnrepository.com
1.在mirrors節(jié)點(diǎn)中添加如下配置:(可選,使用華為開源鏡像站加速下載開源組件)
<mirror> <id>z_mirrors</id> <mirrorOf>*,!releases,!snapshots</mirrorOf> <url>https://repo.huaweicloud.com/repository/maven/</url> </mirror>
2.在servers節(jié)點(diǎn)中添加如下配置:(password從下載的settings.xml文件中獲?。?/p>
<server> <id>releases</id> <username>088dbeef3980f4050f6fc007779eab60_088dbef03980f2d21f98c007dcbde04f</username> <password>************</password> </server> <server> <id>snapshots</id> <username>088dbeef3980f4050f6fc007779eab60_088dbef03980f2d21f98c007dcbde04f</username> <password>************</password> </server>
3.在profiles節(jié)點(diǎn)中添加如下配置
<profile> <id>MyProfile</id> <repositories> <repository> <id>releases</id> <url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_1_0/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>snapshots</id> <url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_2_0/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile>
打開maven的配置文件(windows機(jī)器一般在maven安裝目錄的conf/settings.xml),在<mirrors></mirrors>標(biāo)簽中添加mirror子節(jié)點(diǎn):
<mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共倉(cāng)庫(kù)</name> <url>https://maven.aliyun.com/repository/public</url></mirror>
如果想使用其它代理倉(cāng)庫(kù),可在<repositories></repositories>節(jié)點(diǎn)中加入對(duì)應(yīng)的倉(cāng)庫(kù)使用地址。以使用spring代理倉(cāng)為例:
<repository> <id>spring</id> <url>https://maven.aliyun.com/repository/spring</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots></repository>
1.在mirrors節(jié)點(diǎn)中添加如下配置:(可選,使用阿里開源鏡像站加速下載開源組件)
<mirror> <id>mirror</id> <mirrorOf>!rdc-releases,!rdc-snapshots</mirrorOf> <url>https://maven.aliyun.com/repository/public</url> </mirror>
在settings.xml中添加認(rèn)證信息
在Maven的的默認(rèn)settings.xml中找到servers的部分,添加一個(gè)server配置如下。
<servers> <server> <id>rdc-releases</id> <username>***</username> <password>******</password> </server> <server> <id>rdc-snapshots</id> <username>***</username> <password>******</password> </server></servers>
3.在profiles節(jié)點(diǎn)添加如下配置, 其中 repository 是順序搜索下載包的.
<profile> <id>rdc-private-repo</id> <repositories> <repository> <id>rdc-releases</id> <url>https://repo.rdc.aliyun.com/repository/78947-release-CfzLQ7/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>rdc-snapshots</id> <url>https://repo.rdc.aliyun.com/repository/78947-snapshot-XtuBsZ/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>rdc-releases</id> <url>https://repo.rdc.aliyun.com/repository/78947-release-CfzLQ7/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>rdc-snapshots</id> <url>https://repo.rdc.aliyun.com/repository/78947-snapshot-XtuBsZ/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile>
制品上傳配置
配置好了settings.xml后,在代碼庫(kù)根目錄下的pom.xml加入以下配置:
<!-- 需要發(fā)布二方包 則打開下列的配置 --><distributionManagement> <repository> <id>rdc-releases</id> <url>https://repo.rdc.aliyun.com/repository/78947-release-CfzLQ7/</url> </repository> <snapshotRepository> <id>rdc-snapshots</id> <url>https://repo.rdc.aliyun.com/repository/78947-snapshot-XtuBsZ/</url> </snapshotRepository></distributionManagement>
然后運(yùn)行以下命令即可將制品推送到私有倉(cāng)庫(kù)中:
$ mvn clean deploy -DskipTests
Maven中-DskipTests和-Dmaven.test.skip=true的區(qū)別在使用mvn package進(jìn)行編譯、打包時(shí),Maven會(huì)執(zhí)行src/test/java中的JUnit測(cè)試用例,有時(shí)為了跳過測(cè)試,會(huì)使用參數(shù)-DskipTests和-Dmaven.test.skip=true,這兩個(gè)參數(shù)的主要區(qū)別是:
-DskipTests,不執(zhí)行測(cè)試用例,但編譯測(cè)試用例類生成相應(yīng)的class文件至target/test-classes下。-Dmaven.test.skip=true,不執(zhí)行測(cè)試用例,也不編譯測(cè)試用例類。
雖然mirrors可以配置多個(gè)子節(jié)點(diǎn),但是它只會(huì)使用其中的一個(gè)節(jié)點(diǎn),即默認(rèn)情況下配置多個(gè)mirror的情況下,只有第一個(gè)生效,只有當(dāng)前一個(gè)mirror無法連接的時(shí)候,才會(huì)去找后一個(gè);而我們想要的效果是:當(dāng)a.jar在第一個(gè)mirror中不存在的時(shí)候,maven會(huì)去第二個(gè)mirror中查詢下載,但是maven不會(huì)這樣做!
properties作用:對(duì)應(yīng)profile的擴(kuò)展屬性列表。maven屬性和ant中的屬性一樣,可以用來存放一些值。這些值可以在pom.xml中的任何地方使用標(biāo)記${X}來使用,這里X是指屬性的名稱。屬性有五種不同的形式,并且都能在settings.xml文件中訪問。
<!-- 1. env.X: 在一個(gè)變量前加上"env."的前綴,會(huì)返回一個(gè)shell環(huán)境變量。例如,"env.PATH"指代了$path環(huán)境變量(在Windows上是%PATH%)。 2. project.x:指代了POM中對(duì)應(yīng)的元素值。例如: <project><version>1.0</version></project>通過${project.version}獲得version的值。 3. settings.x: 指代了settings.xml中對(duì)應(yīng)元素的值。例如:<settings><offline>false</offline></settings>通過 ${settings.offline}獲得offline的值。 4. Java System Properties: 所有可通過java.lang.System.getProperties()訪問的屬性都能在POM中使用該形式訪問,例如 ${java.home}。 5. x: 在<properties/>元素中,或者外部文件中設(shè)置,以${someVar}的形式使用。 --><properties> <user.install>${user.home}/our-project</user.install></properties>
<?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"> <pluginGroups></pluginGroups> <proxies></proxies> <servers> <!-- 華為 rds --> <!-- id 需要和 settings profiles.profile.repository.id 和 project 下 distributionManagement.repository.id 保持一致, --> <server> <id>huawei-rdc-repository</id> <username>****yourname***</username> <password>****yourpassword******</password> </server> <server> <id>huawei-rdc-snapshots-repository</id> <username>****yourname***</username> <password>****yourpassword******</password> </server> <!-- 阿里 rds --> <server> <id>aliyun-rdc-repository</id> <username>****yourname***</username> <password>****yourpassword******</password> </server> <server> <id>aliyun-rdc-snapshots-repository</id> <username>****yourname***</username> <password>****yourpassword******</password> </server> <!-- 寶利 rds --> <server> <id>poly-rdc-repository</id> <username>admin</username> <password>ncl@1234</password> </server> </servers> <mirrors> <mirror> <id>huaweiMirror</id> <name>華為云公共倉(cāng)庫(kù)</name> <mirrorOf>central</mirrorOf> <url>https://repo.huaweicloud.com/repository/maven/</url> </mirror> <mirror> <id>aliyunMirror</id> <name>阿里云公共倉(cāng)庫(kù)</name> <mirrorOf>central</mirrorOf> <url>https://maven.aliyun.com/repository/public</url> </mirror> </mirrors> <profiles> <profile> <id>default-profile</id> <properties> <my.repository.url>https://maven.aliyun.com/nexus/content/groups/public</my.repository.url> </properties> <repositories> <repository> <id>central</id> <url>${my.repository.url}</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>snapshots</id> <url>${my.repository.url}</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>${my.repository.url}</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>snapshots</id> <url>${my.repository.url}</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <id>huawei-profile</id> <properties> <my.releases.url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_1_0/</my.releases.url> <my.snapshots.url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_2_0/</my.snapshots.url> </properties> <repositories> <repository> <id>huawei-rdc-repository</id> <url>${my.releases.url}</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>huawei-rdc-snapshots-repository</id> <url>${my.snapshots.url}</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>huawei-rdc-repository</id> <url>${my.releases.url}</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>huawei-rdc-snapshots-repository</id> <url>${my.snapshots.url}</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <id>aliyun-profile</id> <properties> <my.releases.url>https://repo.rdc.aliyun.com/repository/78947-release-CfzLQ7/</my.releases.url> <my.snapshots.url>https://repo.rdc.aliyun.com/repository/78947-snapshot-XtuBsZ/</my.snapshots.url> </properties> <repositories> <repository> <id>aliyun-rdc-repository</id> <url>${my.releases.url}</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>aliyun-rdc-snapshots-repository</id> <url>${my.snapshots.url}</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>aliyun-rdc-repository</id> <url>${my.releases.url}</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>aliyun-rdc-snapshots-repository</id> <url>${my.snapshots.url}</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <id>poly-profile</id> <repositories> <!-- <repository><id>poly-repository</id><name>private maven</name><url>http://10.1.103.106:9080/repository/maven-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository> --> </repositories> <pluginRepositories> <!-- <pluginRepository><id>poly-repository</id><name>private maven</name><url>http://10.1.103.106:9080/repository/maven-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository> --> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>default-profile</activeProfile> <!-- <activeProfile>huawei-profile</activeProfile> --> <activeProfile>aliyun-profile</activeProfile> <!-- <activeProfile>poly-profile</activeProfile> --> </activeProfiles></settings>
https://mirrors.huaweicloud.com/