如何将README.md复制到src/main/resources中? [英] Howto copy README.md into src/main/resources?

查看:101
本文介绍了如何将README.md复制到src/main/resources中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Web应用程序中显示像帮助页面一样的README.md文件.为了不创建重复项,我需要通过mvn从项目路径复制到资源中.

I want to show README.md file like help page in my web application. In order not to create duplicate, I need to copy by mvn from project path into resources.

我该怎么办?

有什么主意吗?

我尝试过:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.3</version>

    <configuration>
        <!-- this is important -->
        <overwrite>true</overwrite>
        <!-- target -->
        <outputDirectory>${basedir}/target/classes</outputDirectory>
        <resources>
            <resource>
                <!-- source -->
                <directory>/</directory>
                <include>
                    <filter>**/README.md</filter>
                </include>
            </resource>
        </resources>
    </configuration>
</plugin>

推荐答案

最简单的解决方案是将适当的文件移动到src/main/resources文件夹,而第二种解决方案可能是这样的:

The simplest solution would be to move the appropriate file(s) to src/main/resources folder whereas the second solution could be like this:

  <build>
    <resources>
      <resource>
        <directory>${project.basedir}</directory>
        <includes>
          <include>README.md</include>
        </includes>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>

无需配置 maven-resources-plugin 即可,由通常的生活周期和资源处理来处理.您唯一需要修改的就是README.md所在的文件夹.如果您希望进行过滤,则还需要添加<filtering>true</filtering>部分.

No need for maven-resources-plugin to be configured this can be handled by the usual life cylcle and resource handling. The only thing you might need to adapt is the folder where the README.md is located. If you like having filtering you need to add the <filtering>true</filtering> part as well.

在构建到src/**的过程中通过Maven复制某些内容通常是一个坏主意,因为这些文件夹受版本控制系统控制,这将导致您不希望进行的未提交的更改.

Copying something via Maven during the build into src/** is in general a bad idea, cause those folders are controled by version control systems which will result in uncommitted changes which you don't like to have.

注意:检查插件的最新版本是明智的(因为2.3是2008年的版本!).当前插件版本的列表可以在以下位置找到: http://maven.apache.org/plugins/

Note: It would be wise to check for up-to-date versions of plugins (cause 2.3 is of 2008!). The list of the current plugin versions can be found here: http://maven.apache.org/plugins/

这篇关于如何将README.md复制到src/main/resources中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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