1癞松、比較常用的
常用命令:compile 編譯
? ? ? ? ? ? ? ? ? package 打包
? ? ? ? ? ? ? ? ? install 將項(xiàng)目打成jar包放入本地倉(cāng)庫(kù)
? ? ? ? ? ? ? ? ?clean ?刪除target
2平窘、創(chuàng)建maven項(xiàng)目
項(xiàng)目的構(gòu)建:
? ? ? ?使用maven構(gòu)建web 項(xiàng)目庄呈,首先進(jìn)入項(xiàng)目的根目錄。
? ? ? ?使用命令:mvn archetype:generate -DgroupId=組織名 -DartifactId=項(xiàng)目名_模塊名 -Dversion=版本號(hào) -Dpackage=代碼所存在的包名
? ? ? ?例如:mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId=maven-archetype-webapp -Dpackage=com.xxx.java
? ? ? 初次建立項(xiàng)目會(huì)需要去中央倉(cāng)庫(kù)去下載一些相關(guān)的依賴包脑题。會(huì)花比較長(zhǎng)的時(shí)間刑峡。下載到本地倉(cāng)庫(kù)之后就不需要再次下載了。
? ? ? maven默認(rèn)的中央倉(cāng)庫(kù)是英國(guó)瓤球,所以因?yàn)閲?guó)內(nèi)訪問(wèn)外網(wǎng)不方便的原因可能導(dǎo)致下載失敗或者及其的慢,所以我們可以把中央倉(cāng)庫(kù)改為國(guó)內(nèi)的敏弃。
? ? ?在/User/xxx/maven/apache-maven-3.5.4/conf/settings.xml中卦羡,有配置鏡像地址的示例,
<!-- mirror
? ? | Specifies a repository mirror site to use instead of a given repository. The repository that
? ? | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
? ? |
? ? | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
? ? <mirror>
? ? ? <id>mirrorId</id>
? ? ? <mirrorOf>repositoryId</mirrorOf>
? </mirrors>
? ? ? <name>Human Readable Name for this Mirror.</name>
? ? ? <url>http://my.repository.com/repo/path</url>
? ? </mirror>
? ? -->
被注釋的部分就是配置鏡像地址方式麦到,將注釋去掉绿饵,配置修改為如下:
其中的url就是國(guó)內(nèi)的中央倉(cāng)庫(kù)地址,其中包含了大部分開(kāi)源的第三方庫(kù)和框架隅要。
安裝jar包到本地倉(cāng)庫(kù)命令
mvn install:install-file -Dfile=commons-httpclients-3.1.jar? -DgroupId=commons-httpclient -DartifactId=commons-httpclient -Dversion=3.1 -Dpackaging=jar