带有Spring Boot的多模块Maven [英] Multi-module maven with Spring Boot

查看:96
本文介绍了带有Spring Boot的多模块Maven的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用Spring Boot使用maven创建一个多模块项目.

I want to know how i can create a multi module project with maven using Spring Boot.

有人可以给我看看父母绒球"和孩子绒球"的例子吗?

Can someone show me an example of the "parent-pom" and "child-pom"?

谢谢

推荐答案

这个问题很难回答,或者太复杂而难以理解,否则我无法解释为什么没有答案.

This question is too simple to answer or too complex to be understood, otherwise I cannot explain why there are no answers.

我会寻求使用如下文件夹结构的解决方案

I would go for a solution that uses a folder structure like the following

project folder
|---pom.xml
|---module1
    |---pom.xml
    |---src
|---module2
    |---pom.xml
    |---src
|---module3
    |---pom.xml
    |---src

我会用pom封装定义项目的pom.xml,例如:

I would define the pom.xml of the project with a pom packaging, e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.7-RELEASE</version>
        <relativePath/>
    </parent>

    <groupId>com.myproject</groupId>
    <artifactId>project</artifactId>
    <packaging>pom</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <modules>
        <module>module1</module>
        <module>module2</module>
        <module>module3</module>
    </modules>

    <name>MySupercoolProject</name>
    <description>What else?</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
      <!-- Put here dependencies shared by your project -->
    </dependencies>
</project>

如您所见,项目的父级将是spring-boot-starter-parent.

As you see, the parent of your project will be a spring-boot-starter-parent.

然后,您的其中一个模块的pom.xml将是,例如:

Then, the pom.xml of one of your modules will be, for instance:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.myproject</groupId>
        <artifactId>project</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <groupId>com.myproject</groupId>
    <artifactId>module1</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <name>Application</name>
    <description>SudenGut application</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <start-class>com.myproject.MyApplication</start-class>
        <java.version>1.8</java.version>
        <tomcat.version>8.0.24</tomcat.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--- this will not be enough to provide a cool app :) -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins
    </build>
</project>

其中主应用程序是module1com.myproject软件包中的MyApplication.java.

where the main application is MyApplication.java in package com.myproject of module1.

除非您有其他子模块(即再次使用pom包装),否则我会在没有主应用程序的情况下将jar包装用于其他模块.

I would use the jar packaging for the other modules without a main application, unless you have other submodules (i.e., pom packaging again).

这篇关于带有Spring Boot的多模块Maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆