文档

pom.xml配置

更新时间:

本文主要对 SOFABoot Web 工程和 Core 工程中的配置文件 pom.xml 进行说明。2 个工程在配置上的区别,主要是<module>内容的不同。

Web 工程的 pom.xml 配置说明

Web 工程完整版 pom.xml 配置,请参考 完整版 pom.xml。下文将就 SOFABoot Web 工程 pom.xml 中的重要标签进行详细介绍。

parent 标签说明

请移步 版本说明,查看最新的 SOFABoot 版本,在工程根目录下的主 pom.xml 中,修改下图所示例项的版本号:

版本号

project 标签说明

<project> 标签中,所声明的工程坐标,包括以下内容,可根据工程需要,进行修改:

  • modelVersion:声明工程描述应遵循的 POM 模型版本。

  • groupId:工程的全球唯一标识符,一般为公司域名或组织域名的反写。示例工程为:com.alipay.sofa

  • artifactId:工程的构件标识符。

  • version:工程版本号。SNAPSHOT 意为快照,说明该项目还在开发中,是不稳定的版本。

  • packaging:工程产生的构件类型,例如 jar、war、ear、pom。

  • name:工程的名称,非必选项。

  • url:工程主页的 URL,非必选项。

了解这些元素的具体含义,可参见 Apache Maven 官方文档(英文)

dependencies 标签说明

<dependencies> 标签中,声明了工程相关的所有依赖,说明如下:

模块标签

工程原型默认生成 app/endpointapp/web 两个模块(module):

<modules>
     <module>app/endpoint</module>
     <module>app/web</module>
</modules>

endpoint 模块

endpoint 模块是 SOFAREST 的服务模块,对外提供 SOFAREST 服务。SOFABoot Web 工程的 app/endpoint 模块中,默认添加了 SOFAREST 的依赖。

<dependency>
  <groupId>com.alipay.sofa</groupId>
  <artifactId>rest-enterprise-sofa-boot-starter</artifactId>
</dependency>

SOFABoot 使用一系列的 {XXXXXX}-sofa-boot-starter 来统一管理中间件的依赖。例如,您需要新增对 RPC 中间件的依赖,可以在 pom.xml 中添加以下配置:

<dependency>
    <groupId>com.alipay.sofa</groupId>
    <artifactId>rpc-enterprise-sofa-boot-starter</artifactId>
</dependency>

web 模块

web 模块是启动模块,包含 main 函数后可以直接运行,同时将全局的配置文件以及静态资源等放在这个模块下。

打包部署说明

SOFABoot Web 工程在 Web 模块中配置 构建(build),使用 spring-boot-maven-plugin 作为构建工具并在工程根目录的 target 下生成一个 fat JAR(.jar)包。该 fat JAR 包是一个可部署单元,有本地和云端 2 种部署方式:

  • 本地部署:可运行 java -jar 命令启动该 .jar 包;

  • 云端部署:当上传到 SOFAStack 平台进行部署时,只需要上传该 fat JAR 文件,SOFABoot 技术栈会自动配合 SOFAStack 的部署平台为您部署。

build 标签示例如下:

<build>
    <plugins>
        <!-- http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <!-- http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html -->
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.4.2.RELEASE</version>
            <configuration>
                <!-- 可部署的 fat JAR 打包在工程的根目录的 target 下面 -->
                <outputDirectory>../../target</outputDirectory>
                <classifier>executable</classifier>
            </configuration>
            <executions>
                <execution>
                    <goals>
                    <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Core 工程的 pom.xml 配置说明

Core 工程完整版 pom.xml 配置,请参考 完整版 pom.xml。下文将就 SOFABoot Core 工程 pom.xml 中的重要标签进行详细介绍。

parent 标签说明

请移步 版本说明,查看最新的 SOFABoot 版本,在工程根目录下的主 pom.xml 中,修改下图所示例项的版本号:

版本号

project 标签说明

请您参考上文 Web 工程中的相关说明。

dependencies 标签说明

<dependencies> 标签中,声明了工程相关的所有依赖,说明如下:

模块标签

工程原型默认生成 APPNAME-facadeAPPNAME-service 两个模块(module):

<modules>
     <module>APPNAME-facade</module>
     <module>APPNAME-service</module>
</modules>

facade 模块

facade 模块用于定义服务的接口,同时在使用 RPC 中间件时方便将这个模块打包的 JAR 分发给服务的调用方。

service 模块

service 模块包含的配置信息包括 全局配置应用的日志配置文件 以及 技术栈相关的配置信息service 模块引入 facade 模块和 RPC 中间件需要的所有依赖。以下是 service 模块的 pom.xml

  • 下载 service module 的 pom.xml

  • service module 的 pom.xml 说明

    <!-- facade 依赖-->
    <dependency>
         <groupId>com.alipay.sofa</groupId>
         <artifactId>APPNAME-facade</artifactId>
    </dependency>
    <!--引入了 RPC 中间件需要的所有依赖-->
    <dependency>
         <groupId>com.alipay.sofa</groupId>
         <artifactId>rpc-enterprise-sofa-boot-starter</artifactId>
    </dependency>

打包部署说明

关于打包部署方式,请您参考上文 Web 工程中 打包部署说明

  • 本页导读 (0)
文档反馈