java 读写doc maven,在JavaDoc中使用Maven属性

本文介绍如何使用Maven Javadoc Plugin将项目版本等属性注入到JavaDoc注释中,通过两步操作实现:首先从pom.xml加载属性,然后在代码中静态字段读取并设置Javadoc属性。具体步骤包括配置资源文件、启用Maven过滤和创建MVNLinksHolder类来获取属性。
摘要由CSDN通过智能技术生成

Is it possible to expand the maven properties' scope on javadocs using Maven Javadoc Plugin? E.g.

/**

* My Awesome Class

* @version ${project.version}

**/

解决方案

I think you try like this. This is two step process:

First is to load the pom property into static field

Second to use the static field to set the javadoc property

Create a app.properties in src/main/resources with content like this

application.version=${project.version}

then enable maven filtering like this

src/main/resources

true

In application code just read properties file

public class MVNLinksHolder{

public static String version = "";

public MVNLinksHolder(){

ClassPathResource resource = new ClassPathResource( "app.properties" );

Properties p = new Properties();

InputStream inputStream = null;

try {

inputStream = resource.getInputStream();

p.load( inputStream );

version = p.getProperty("application.version");

}

catch ( IOException e ) {

LOGGER.error( e.getMessage(), e );

}

finally {

Closeables.closeQuietly( inputStream );

}

}

}

Then use it to set the version

/**

* My Awesome Class

* @version = {@value MVNLinksHolder#version}

**/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值