ovn*_*nia 10 java javadoc maven
是否可以使用Maven Javadoc插件在javadocs上扩展maven属性的范围?例如
/**
* My Awesome Class
* @version ${project.version}
**/
Run Code Online (Sandbox Code Playgroud)
我想你可以这样尝试。这是两步过程:首先将 pom 属性加载到静态字段中,然后使用静态字段设置 javadoc 属性
创建一个包含类似内容的app.propertiesinsrc/main/resources
application.version=${project.version}
Run Code Online (Sandbox Code Playgroud)
然后像这样启用maven过滤
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
在应用程序代码中只需读取属性文件
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 );
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后用它来设置版本
/**
* My Awesome Class
* @version = {@value MVNLinksHolder#version}
**/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
455 次 |
| 最近记录: |