maven

  1. 默認情況下,java源碼應該放在src/main/java/……目錄下,測試源碼應該放在src/main/test/……目錄下
  2. mvn clean compile生成.class文件,mvn clean install生成.class文件和.jar文件
  3. 當倉庫裏不存在pom文件中的依賴時,第一次會報這樣的錯誤:
    [ERROR] Failed to execute goal on project hello: Could not resolve dependencies for project com.cisco.mytest:hello:jar:1.0.0-SNAPSHOT: Could not find artifact junit:junit:jar:4.13 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
    然後在~/.m2/repository本地倉庫中會有兩個文件:***.jar.lastUpdated***.pom.lastUpdated
    當再次運行mvn時,會報這樣的錯誤:
    [ERROR] Failed to execute goal on project hello: Could not resolve dependencies for project com.cisco.mytest:hello:jar:1.0.0-SNAPSHOT: Failure to find junit:junit:jar:4.13 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
  4. mvn clean compile(會生成.class文件)
    mvn clean test(會執行src目錄下的test文件夾裏的內容,執行之前會執行compile)
    mvn clean package(會生成.jar文件,在執行之前會執行test)
    mvn clean install(會將.jar文件安裝到~/.m2/repository,在執行之前會執行package)
    5.如果在java源碼中加入包信息語句package com.cisco.mytest.hello;,那麼在target目錄下就會生成帶有相同目錄結構的文件夾com/cisco/mytest/hello和class文件,如果不加包信息,則不生成上述文件夾,只有class文件
    6.在java源碼中加入包信息語句package com.cisco.mytest.hello;,那麼我在class目錄下運行java HelloWorld會提示錯誤: 找不到或無法加載主類 HelloWorld。應該在src/main/java目錄下運行java com.cisco.mytest.hello.HelloWorld,在合適的目錄下,運行帶有包信息的命令
  5. 倉庫路徑與座標的關係爲:groupId/artifactId/version/artifactId-version.packaging,例如依賴org.sonatype.nexus:nexus-indexer:2.0.0,其對應的路徑爲org/sonatype/nexus/nexus-indexer/2.0.0/nexus-indexer-2.0.0.jar,jar包文件名的格式爲artifactId-version.packaging,所以artifactId應該使用實際項目名作爲前綴,比如nexus-indexer
  6. 聚合模塊:聚合模塊是頂層模塊,在其POM文件中,<packaging>應該爲pom(默認爲jar),無<dependency>,子模塊寫在<module>中,<module>中的子模塊名字必須與其目錄文件名一致,所以子模塊目錄文件名應該與artifactId一致,這樣<module>就與artifactId一致了
  7. 繼承模塊:其POM文件中的<packaging>也爲pom、
  8. 一般都將繼承模塊和聚合模塊放在一起融合使用
發佈了98 篇原創文章 · 獲贊 41 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章