Maven deploy配置方法詳解
作用
在本地的pom文件配置好之后,執(zhí)行deploy命令,可以將maven所打的jar包上傳到遠(yuǎn)程的repository,便于其他開發(fā)者和工程共享。
pom.xml配置
首選,在pom文件中project標(biāo)簽下添加如下代碼:
<distributionManagement> <repository> <id>releases</id> <name>Internal Releases</name> <url>http://localhost:8081/nexus/content/repositories/thirdparty</url> </repository> <snapshotRepository> <id>releases</id> <name>Internal Releases</name> <url>http://localhost:8081/nexus/content/repositories/thirdparty</url> </snapshotRepository> </distributionManagement>
此時,執(zhí)行deploy命令,會返回401錯誤,則需要用戶驗證或驗證的信息有誤。
setting.xml文件配置
在setting配置文件的servers標(biāo)簽下添加如下代碼:
<server> <id>releases</id> <username>admin</username> <password>admin</password> </server>
PS:其中此處的id,必須為pom文件中配置的repository的id。
注意事項
一般繼承 parent 的version會按照如下格式寫:
<parent> <groupId>module.some</groupId> <artifactId>module_parent</artifactId> <version>${parent.version}</version> </parent>
這樣寫方便統(tǒng)一管理版本信息,但發(fā)布到maven私服之后,maven 會試圖下載 module_parent 的 ${parent.version} 的 jar。顯然,這個jar是不存在的。那么為什么已經(jīng)指定了 parent.version 的值了卻沒有解析呢?這是因為deploy 的過程中,parent 標(biāo)簽里的變量是不會解析的,必須是一個常量。
結(jié)果
執(zhí)行maven deploy命令成功之后,登錄私服進(jìn)行查詢,即可看到對應(yīng)的jar包。
maven deploy命令打包到私服
<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>com.zeelan.app</groupId> <artifactId>seller-auth</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <!-- 項目編碼 --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <lombok.version>1.16.10</lombok.version> <mybatis.paginator.version>1.2.17.2</mybatis.paginator.version> <hibernate.validator.version>5.1.2.Final</hibernate.validator.version> <validation.api.version>1.1.0.Final</validation.api.version> </properties> <!-- 遠(yuǎn)程倉庫地址 --> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Team Nexus Repository</name> <url>http://192.168.0.126:8081/nexus/content/groups/public</url> </pluginRepository> </pluginRepositories> <!-- 配置遠(yuǎn)程發(fā)布到私服,mvn deploy --> <distributionManagement> <!-- 定義releases庫的坐標(biāo) --> <repository> <id>releases</id> <name>Nexus Release Repository</name> <url>http://192.168.0.126:8081/nexus/content/repositories/releases/</url> </repository> <!-- 定義snapshots庫 --> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://192.168.0.126:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> <!-- 項目有依賴的所有jar坐標(biāo)配置 --> <dependencies> <!-- lombok jar --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency> <!-- mybatis分頁插件jar --> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> <version>${mybatis.paginator.version}</version> </dependency> <!-- hibernate validator驗證jar --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>${hibernate.validator.version}</version> </dependency> <!-- hibernate validtor需要的依賴 jar --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>${validation.api.version}</version> </dependency> </dependencies> <build> <finalName>seller-auth</finalName> <!-- 插件庫聲明 --> <plugins> <!-- 配置運(yùn)行環(huán)境JDK版本 --> <plugin> <artifactId>maven-compiler-plugin</artifactId> <extensions>true</extensions> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <!-- 將源碼打包插件 --> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- deploy時只上傳jar包到遠(yuǎn)程倉庫的配置 --> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> <executions> <execution> <id>default-deploy</id> <phase>deploy</phase> <goals> <goal>deploy</goal> </goals> <!-- skip默認(rèn)deploy插件的執(zhí)行 --> <configuration> <skip>true</skip> </configuration> </execution> <execution> <id>deploy-file</id> <phase>deploy</phase> <goals> <goal>deploy-file</goal> </goals> <configuration> <!-- 開發(fā)階段上傳到snapshot倉庫,上線階段上傳到release倉庫 --> <repositoryId>${project.distributionManagement.snapshotRepository.id}</repositoryId> <url>${project.distributionManagement.snapshotRepository.url}</url> <file>${project.build.directory}/${project.artifactId}.jar</file> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
執(zhí)行 mvn deploy就能打包到私服上了!
mvn -clean配置清除插件,然后在執(zhí)行命令可以清除target下的文件
mvn-clean package 本地打包,jar/war/等根據(jù)<packaging>jar/war</packaging>控制
mvn -e 查看打包過程的錯誤信息
mvn -v查看mavne版本信息等等
到此這篇關(guān)于Maven deploy配置方法詳解的文章就介紹到這了,更多相關(guān)Maven deploy配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java實(shí)現(xiàn)memcache服務(wù)器的示例代碼
本篇文章主要介紹了java實(shí)現(xiàn)memcache服務(wù)器的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04基于SpringBoot實(shí)現(xiàn)代碼在線運(yùn)行工具
這篇文章主要介紹了如何利用SpringBoot實(shí)現(xiàn)簡單的代碼在線運(yùn)行工具(類似于菜鳥工具),文中的示例代碼講解詳細(xì),需要的可以參考一下2022-06-06@FeignClient的使用和Spring?Boot的版本適配方式
這篇文章主要介紹了@FeignClient的使用和Spring?Boot的版本適配方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03使用Mybatis Plus整合多數(shù)據(jù)源和讀寫分離的詳細(xì)過程
這篇文章主要介紹了Mybatis Plus整合多數(shù)據(jù)源和讀寫分離的詳細(xì)過程,mybatisplus可以整合阿里的分布式事務(wù)組件seata,本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2021-09-09Mybatis中通過generator生成mapper、Dao、mapper.xml的方法
這篇文章主要介紹了Mybatis中通過generator生成mapper、Dao、mapper.xml的方法,需要的朋友可以參考下2017-01-01IntelliJ IDEA自定義代碼提示模板Live Templates的圖文教程
這篇文章主要介紹了IntelliJ IDEA自定義代碼提示模板Live Templates,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03