maven 多項目管理--demo

以前開發的過程當中,是按照功能劃分包,今天看一個Grpc的demo時發現博主使用maven進行多項目管理,感受很是的方便,學習一下!!!java

實驗目的:

Maven項目TestPom01要使用TestPom中的Factory類maven

操做步驟:

一、使用Idea打開項目根目錄,加載項目
二、在根目錄下建立pom.xml,書寫要加載的模塊

三、點擊右側的Maven Project,點擊加號將根目錄下的pom.xml及各個模塊的xml文件加載(這纔算正式的將maven項目導入)
四、點擊下側的Terminal,進入項目根目錄,執行mvn install,將項目安裝到本地
五、進行測試學習

代碼實現:

根目錄下的pom.xml:測試

<modelVersion>4.0.0</modelVersion>
    <groupId>nwpu.cn</groupId>
    <artifactId>Mavenandmaven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>TestPom</module>
        <module>TestPom01</module>
    </modules>

TestPom項目
pom.xml.net

<modelVersion>4.0.0</modelVersion>
    <groupId>nwpu.cn</groupId>
    <artifactId>TestPom</artifactId>
    <version>1.0-SNAPSHOT</version>

Factory.javacode

package learning;
public class Factory {
    public  static String createMessage(){
        String message = "hello maven1";
        return message;
    }
}

TestPom01
pom.xmlxml

<modelVersion>4.0.0</modelVersion>
    <groupId>nwpu.cn</groupId>
    <artifactId>TestPom01</artifactId>
    <version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>nwpu.cn</groupId>
        <artifactId>TestPom</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
</project>

Test.javablog

package learning;
public class Test {
    public static void main(String[] args) {
        String message = Factory.createMessage();
        System.out.println(message);
    }
}

測試結果

參考博客

在maven項目中如何引入另一個項目
用 Maven 管理多模塊項目的最佳實踐ci

相關文章
相關標籤/搜索