maven是一個項目構建和管理的工具,提供了幫助管理 構建、文檔、報告、依賴、scms、發布、分發的方法。可以方便的編譯代碼、進行依賴管理、管理二進制庫等等。maven的好處在于可以將項目過程規范化、自動化、高效化以及強大的可擴展性利用maven自身及其插件還可以獲得代碼檢查報告、單元測試覆蓋率、實現持續集成等等前言: maven項目也是一個項目,類似于javaPRoject,javaWebProject,就是多了些功能,其他也沒啥,所以大家接觸的時候不要害怕!1 . 幫你下載jar包 maven項目會有一個 pom.xml文件, 在這個文件里面,只要你添加相應配置,他就會自動幫你下載相應jar包,不用你鋪天蓋地的到處搜索你需要的jar包了,下面是示范配置文件pom.xml<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>exam</groupId> <artifactId>exam_3</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version><dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.0.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.0.5.RELEASE</version> </dependency> </dependencies> </project>以上主要看的<dependencies>結點里面的內容, 里面每配置一個<dependency>, <groupId>org.springframework</groupId> 項目名 <artifactId>spring-webmvc</artifactId> 項目模塊 <version>3.0.5.RELEASE</version> 項目版本 maven都會通過,項目名-項目模塊-項目版本來maven在互聯網上的代碼庫中下載相應jar包。 所以這就是maven的功能之一,幫你下載jar包2 . 尋找依賴,幫你下載依賴 尋找jar包是第一基本功能,尋找依賴在這個是在這個基礎上的功能。 在maven的代碼庫中,每一個jar包也有自己的 pom.xml文件,而這個文件里面也會有<dependency>配置,什么依賴范圍我就不細說了,我想表達的就是,只要你配置的jar包所依賴的其他jar包都會被maven自動下載下來。 例如: 你配置了 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>2.6</version> </dependency>你要maven幫你下載spring-core-2.6.jar包 而這個jar包里面需要用到commons-logging.jar這個包, 這叫就依賴,spring-core-2.6.jar依賴于commons-logging.jar。 這就是maven第二個作用,幫你下載依賴包。3 . 熱部署,熱編譯 意思就是,在你web項目已經運行的時候,修改代碼的能直接被web服務器所接受,就不需要你 重啟服務器了,或者重新部署代碼了,而且你可以直接通過maven 打包war或者jar項目。
新聞熱點
疑難解答