欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Maven 使用介紹
創(chuàng )建project
先去官方網(wǎng)站下載一個(gè)最新版本http://maven.apache.org/download.cgi. 下載后解壓,使用之前最好先將maven的bin目錄設置到path環(huán)境變量里面。
maven無(wú)非也就是用來(lái)build一個(gè)project的,直接先上一個(gè)例子,在命令行下輸入下面的命令:
mvn archetype:generate DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=myapp
mvn就是maven的命令行程序,archetype:generate中的archetype是plugin的名字,generate是goal的名字,命令行后面的是一些參數。關(guān)于archetype和goal以及后面的參數,后面再細說(shuō)。
如果是第一次運行,這個(gè)過(guò)程會(huì )有點(diǎn)慢,maven需要下載一些依賴(lài)項,中間如果有輸入提示信息,直接回車(chē)使用默認值就可以了。這條命令執行完后,會(huì )在你的當前目錄下生成一個(gè)名為myapp的目錄:
注意這個(gè)目錄結構,src/main/java 和 src/test/java 是不能改動(dòng),不然maven會(huì )無(wú)法找到源文件。下面是maven一個(gè)標準的目錄結構:
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/scripts Application/Library scripts
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
另外maven還生成了一個(gè)重要的文件pom.xml,maven就是通過(guò)這個(gè)文件來(lái)來(lái)管理整個(gè)project,可以理解位類(lèi)似于eclipse的.project文件。默認生成的pom.xml文件的內容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* 1-1 */
<project xmlns="
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.1.0.1</version>
<packaging>jar</packaging>
<name>myapp</name>
<url>
http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
解釋一下這個(gè)xml文件的內容:
modelVersion: 這個(gè)XML文件所使用的POM格式的版本
groupId: 相當于這個(gè)project的所有者或者機構的一個(gè)標識,一般是com.company.xxx這種格式
artifactId:  這個(gè)project最后所生成的文檔(jar、war)的名字,比如對于junit這個(gè)開(kāi)源的project,它的artifactId就是junit
packaging: 這個(gè)project的打包的類(lèi)型,一般是war、jar等值
version: project的版本
name: project的名字,生成文檔等內容的時(shí)候會(huì )用的這個(gè)名字
這個(gè)project創(chuàng )建好后和普通的project沒(méi)有什么不同,我們直接往里面放源代碼進(jìn)行開(kāi)發(fā)就可以了,如果有目錄想修改的也完全可以。
POM & archetype
archetype就是一個(gè)project的模板,上面我們生成的project就是用默認的archetype生成的。如果使用不同的archetype,生成的project結構會(huì )有所不同。 一個(gè)archetype指明了
1) 項目的目錄結構以及什么目錄是放source code,哪些是放test source code,哪些目錄是放resource的。
2) 一個(gè)默認的pom.xml文件,這個(gè)默認的pom.xml文件中的groupId,artifactId,version用占位符表示,在創(chuàng )建project的時(shí)候通過(guò)參數傳進(jìn)來(lái)。
pom.xml文件的POM全稱(chēng)是Project Object Model,這個(gè)文件對于maven的使用者來(lái)說(shuō)是一個(gè)和maven交互的渠道,pom.xml包含了一個(gè)maven project的配置,一個(gè)project該如何編譯打包,project有哪些依賴(lài)項等等。
仔細看一下我們前面創(chuàng )建project的命令:mvn archetype:generate DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=myapp
1) archetype:generate, 這是一個(gè)maven的plugin,用來(lái)從一個(gè)archetype創(chuàng )建一個(gè)project,關(guān)于plugin后面再說(shuō)。
2) DarchetypeGroupId,這個(gè)就是指的archetype的groupid,也就是說(shuō)是用的哪個(gè)archetype,或者說(shuō)用哪個(gè)項目模板。
3) 后面的兩個(gè)參數,用來(lái)放大pom.xml文件里面,作為當前創(chuàng )建的project的描述信息。
Project創(chuàng )建好了,看如何去編譯,直接進(jìn)入的project的目錄,在命令行下:
mvn compile
編譯完后maven會(huì )創(chuàng )建一個(gè)target目錄去保存編譯結果。 我們需要編譯成一個(gè)什么樣的內容,以及要輸出到什么地方等等,都是可以在pom.xml文件里面配置的,但是因為我們目前并沒(méi)有指定這些內容,所以maven會(huì )使用默認值。
我們還可以用maven執行test:
mvn test
第一次執行時(shí),maven會(huì )去下載一些依賴(lài)項。另外要注意的時(shí),如果我們更改了默認的目錄結構,maven會(huì )因為找bu到test而無(wú)法去執行test。如果只需要編譯test可以執行:
mvn test-compile
要把項目打包,執行:
mvn package
mvn會(huì )根據pom.xml里面的packaging選項打包成相應的文件。
repository & dependency
maven里面有一個(gè)repository的概念,當我們的項目依賴(lài)于某個(gè)jar時(shí),maven會(huì )去repository里面去找。repository分兩種,一種是遠程的,一種是本地的。如果有幾個(gè)project都用到j(luò )unit,我們可以把junit放在repository里面,幾個(gè)project可以公用,節約存儲空間而且方便管理,這個(gè)repository的位置可以在pom.xml里面設置。
本地的默認的路徑是安裝用戶(hù)的目錄下的 .m2\repository 文件夾。如果一個(gè)依賴(lài)項在本地的repository里面沒(méi)有,那么maven會(huì )去他自己的遠程的repositoryhttp://repo.maven.apache.org/maven2 去下載后放到本地的repository里面。
也就是說(shuō),我們如果我們的project需要要引用一個(gè)依賴(lài)項,我們只需要在pom.xml文件中進(jìn)行配置,maven會(huì )自動(dòng)幫我們去引用。 我們之前的創(chuàng )建project里面需要寫(xiě)單元測試,引用到了junit,看pom中的配置:
1
2
3
4
5
6
7
8
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
每一個(gè)需要為每一個(gè) dependency 指明groupId,artifactId,version。scope很簡(jiǎn)單,意思是說(shuō)我們需要怎么引用,比如我們上面的例子里面設置的是test,意思是說(shuō)只在test里面引用junit。 但是我們如何知道groupId,artifactId和version呢? 比如我現在想引用log4j,這個(gè)幾個(gè)值怎么填? 可以去http://mirrors.ibiblio.org/maven2/ 上去查找。比如log4j,我們就在上面這個(gè)地址加上log4j,也就是http://mirrors.ibiblio.org/maven2/junit/。進(jìn)去后會(huì )有一個(gè)maven-metadata.xml,打開(kāi)就可以知道這些值了然后添加這個(gè)dependency了。
如果要把一個(gè)project安裝到本地的repository里面,可以執行下面的命令:
mvn install
到這里就說(shuō)完了創(chuàng )建,編譯,測試,打包以及安裝,大部分的項目也就是做這些事情。
再介紹幾個(gè)其它命令:
mvn site : 為你的project創(chuàng )建一個(gè)站點(diǎn)
mvn clean: 清除target目錄下的所有文件
mvn eclipse:eclipse :為project生成eclipse的工程文件和classpath文件
build lifecycle & build phase & goal
maven有一套build的生命周期,是按照一套順序走下來(lái)的,這一套順序就叫一個(gè)生命周期(lifecycle)。maven內置三種生命周期:default, clean 和 site。一個(gè)生命周期分為多個(gè)build phase,下面是default生命周期全部的build phase:
validate:validate the project is correct and all necessary information is available.
initialize:initialize build state, e.g. set properties or create directories.
generate-sources:generate any source code for inclusion in compilation.
process-sources:process the source code, for example to filter any values.
generate-resources:generate resources for inclusion in the package.
process-resources:copy and process the resources into the destination directory, ready for packaging.
compile:compile the source code of the project.
process-classes:post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.
generate-test-sources:generate any test source code for inclusion in compilation.
process-test-sources:process the test source code, for example to filter any values.
generate-test-resources:create resources for testing.
process-test-resources:copy and process the resources into the test destination directory.
test-compile:compile the test source code into the test destination directory
process-test-classes:post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above.
test:run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
prepare-package:perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above)
package:take the compiled code and package it in its distributable format, such as a JAR.
pre-integration-test:perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-test:process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test:perform actions required after integration tests have been executed. This may including cleaning up the environment.
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.
這些build phase是按照順序執行的,如果執行后面的build phase,前面的build phase 也會(huì )被執行。例如如果執行:
mvn deploy
前面的install、verify一直到validate這些build phase都會(huì )執行。
每一個(gè)build phase是由goal組成的,一個(gè)goal其實(shí)就是一個(gè)任務(wù),一個(gè)goal可以關(guān)聯(lián)到一個(gè)build phase也可以不關(guān)聯(lián)到任何build phase 。 不關(guān)聯(lián)到任何phase的goal是可以獨立執行的,例如:
mvn clean dependency:copy-dependencies package
上面的命令會(huì )導致先執行clean這個(gè)phase,然后拷貝依賴(lài)項,最后打包。注意,這里clean這個(gè)goal是clean這個(gè)lifecycle里面的一個(gè)goal,所以可以看到不同lifecycle的build phase和goal是可以混合在一起執行的。 如果一個(gè)goal被綁定到多個(gè)phase上,那么goal就會(huì )被執行多次。
phase的順序是已經(jīng)固定的,如果一個(gè)phase沒(méi)有綁定到任何goal,那么phase就不會(huì )被執行。 一個(gè)goal可以通過(guò)兩種方式綁定到一個(gè)phase,一個(gè)是指定packaging,另一個(gè)就是plugin。
packaging&plugin
plugin就是用來(lái)向maven提供goal的。一個(gè)plugin里面可以有多個(gè)goal,這就是為什么我們在指明goal時(shí),前面會(huì )用一個(gè)冒號與plugin的名字。
一個(gè)plugin自己可以指定自己的goal綁定到哪個(gè)lifecycle的哪一個(gè)Phase上,另外也可以配置一個(gè)goal綁定到哪個(gè)phase上??梢栽趐om.xml里面配置。 看兩個(gè)配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<configuration>
<models>
<model>src/main/mdo/maven.mdo</model>
</models>
<version>4.0.0</version>
</configuration>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
這個(gè)就在當前的lifecycle里面添加了一個(gè)名字叫java的goal,這goal會(huì )根據自己的配置去綁定到一個(gè)phase,在phase執行的時(shí)候這個(gè)goal會(huì )執行。并且在這個(gè)配置里面,可以指定多個(gè)execution來(lái)讓這個(gè)goal執行多次。
看另一個(gè)示例配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
<plugin>
<groupId>com.mycompany.example</groupId>
<artifactId>display-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>process-test-resources</phase>
<goals>
<goal>time</goal>
</goals>
</execution>
</executions>
</plugin>
這個(gè)名為time的goal把自己綁定到了process-test-resource這個(gè)phase上。
在默認情況下,并不是所有的phase都綁定了goal,比如clean這個(gè)lifecycle是有三個(gè)phase的,但是只有其中的一個(gè)名為clean的phase默認綁定了一個(gè)clean:clean goal,其它兩個(gè)phase默認沒(méi)有綁定任何goal。
之前已經(jīng)提到過(guò)packaging,在pom.xml可以指定packaging,每種packaging都設定了一組phase和goal之間的綁定關(guān)系。在default lifecycle下,當packaging為 ejb/ejb3/jar/par/rar/war 其中之一的值的時(shí)候,只有以下的phase綁定了goal,具體如下:
process-resourcesresources:resources
compilecompiler:compile
process-test-resourcesresources:testResources
test-compilecompiler:testCompile
testsurefire:test
packagejar:jar
installinstall:install
deploydeploy:deploy
總結
首先搞清楚maven的project的目錄結構,然后理解maven的lifecycle,lifecycle是由build phase組成,每一個(gè)build phase會(huì )綁定到goal。goal是由plugin提供的。 每一種packaging的值都表明了一定的phase和goal之間的綁定關(guān)系。
另外一個(gè)很重要的就是dependency,我們要在項目中引用一個(gè)依賴(lài),只需要在pom.xml指定依賴(lài)的名字和版本,maven會(huì )自動(dòng)去遠程的repository下載,然后放到本地的repository里面,這樣以后所有的project都可以共用
其它細節可以參考http://maven.apache.org/guides/index.html。
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
徹底理解maven
Maven、Nexus、SVN、Hudson 以及團隊異地開(kāi)發(fā)那些事(1)
[翻譯]Maven五分鐘入門(mén)
Maven編譯代碼的相關(guān)命令
換個(gè)視角看 Maven:一個(gè)領(lǐng)域平臺的優(yōu)美設計
maven3常用命令、java項目搭建、web項目搭建詳細圖解
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久