轉+總結!! maven的package與install命令區別


如果b項目依賴a項目,而a打了包(package),jar僅僅時打到了a項目的target下。這時編譯b項目,還是會報錯,找不到所依賴的a項目,說明b項目在本地倉庫是沒有找到它所依賴的a項目。

然后,我install a項目這時,有以下日志,[INFO] Installing G:\projects\a\target\a-0.0.1-SNAPSHOT.jar to F:\repository\com\chenjun\a\0.0.1-SNAPSHOT\a-0.0.1-SNAPSHOT.jar
[INFO] Installing G:\projects\a\pom.xml to F:\repository\com\chenjun\a\0.0.1-SNAPSHOT\a-0.0.1-SNAPSHOT.pom,

說明a項目已安裝到本地倉庫了,並且是jar和pom同時安裝的.

這時候去compile b項目,編譯通過.

總之,package是把jar打到本項目的target下,而install時把target下的jar安裝到本地倉庫,供其他項目使用.

(-----以上轉自:http://blog.csdn.net/bawcwchen/article/details/46957627)

 

maven常用命令

package:負責打包項目到本項目target路徑下(take the compiled code and package it in its distributable format, such as a Jar/War/Ear.)

clean:清除target目錄的文件

install:生成jar包並安裝到本地maven倉庫(xx/.m2/xx),可供其他項目調用(install the package into the local repository, for use as a dependency in other projects locally)

compile:編譯項目(compile the source code of the project)

test:執行測試代碼(test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed)

平時打包要發布的項目(指定環境dev/test/prod):mvn clean package -Dmaven.test.skip=true -Pprod 

-P xxx 會激活項目下的pom.xml配置的<profiles>標簽下id為xxx 的相關配置

 

 

Maven Phases

Although hardly a comprehensive list, these are the most common default lifecycle phases executed.

  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

There are two other Maven lifecycles of note beyond the default list above. They are

  • clean: cleans up artifacts created by prior builds
  • site: generates site documentation for this project

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM