Maven site(站点)

本文介绍了如何在Maven项目中使用maven-site-plugin插件生成Web站点,展示了如何配置并执行`mvnsite`命令,以及遇到的问题和解决方法。
摘要由CSDN通过智能技术生成

Maven site(站点)

Maven 不仅仅是一款项目构建和依赖管理工具,它还能够聚合项目信息,促进项目团队间地交流。POM 中可以包含各种项目信息,例如:项目描述、SCM 地址、许可证信息,开发者信息等。用户可以使用 Maven 提供的 maven-site-plugin 插件让 Maven 生成一个 Web 站点, 以站点的形式发布以上信息。

以 secondMaven 项目为例,修改其 pom.xml 中的配置,添加该插件到项目中。

<?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">
    <parent>
        <artifactId>maven</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>secondMaven</artifactId>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!--外部依赖-->
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>helloMaven</artifactId>
            <!--依赖范围-->
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <!--依赖所在位置-->
            <systemPath>D:\workspace\IdeaCode\maven\helloMaven\target\helloMaven-1.0-SNAPSHOT.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!--添加site 插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
        </plugins>
    </build>

</project>

打开命令行窗口,跳转到 secondMaven 的目录中,执行如下 mvn 命令。

mvn site

执行结果如下。

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.example:secondMaven:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for org.example:helloMaven:jar should use a variable instead of a hard-coded path D:\workspace\IdeaCode\maven\helloMaven\target\helloMaven-1.0-SNAPSHOT.jar @ line 28, column 25
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ----------------------< org.example:secondMaven >-----------------------
[INFO] Building secondMaven 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-site-plugin:3.7.1:site (default-site) @ secondMaven ---
[WARNING] Input file encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:3.5.0
[INFO] 15 reports detected for maven-project-info-reports-plugin:3.5.0: ci-management, dependencies, dependency-info, dependency-management, distribution-management, index, issue-management, licenses, mailing-lists, modules, plugin-management, plugins, scm, summary, team
[INFO] Rendering site with default locale English (en)
[WARNING] No project URL defined - decoration links will not be relativized!
[INFO] Rendering content with org.apache.maven.skins:maven-default-skin:jar:1.2 skin.
[INFO] Generating "Dependencies" report  --- maven-project-info-reports-plugin:3.5.0:dependencies
[INFO] Generating "Dependency Information" report --- maven-project-info-reports-plugin:3.5.0:dependency-info
[INFO] Generating "About" report         --- maven-project-info-reports-plugin:3.5.0:index
[INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:3.5.0:plugin-management
[INFO] Generating "Plugins" report       --- maven-project-info-reports-plugin:3.5.0:plugins
[INFO] Generating "Summary" report       --- maven-project-info-reports-plugin:3.5.0:summary
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.734 s
[INFO] Finished at: 2023-12-31T16:11:24+08:00
[INFO] ------------------------------------------------------------------------

Maven 命令运行完毕后,可以在项目的 target\site 目录下找到 Maven 生成的站点文件,如下图。

双击打开 index.html 查看站点。

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值