如何在JAVADOC注释中使用变量?

时间:2022-11-19 15:16:17

I wish to refer to a particular URL in JAVADOC comments in a project. However, I know that the URL may change in the near future. So, I was looking for a functionality that allows one to use a single variable in place of this URL throughout the project. So that if needed, it can easily be changed, but I could not find one.

我希望在项目中引用JAVADOC注释中的特定URL。但是,我知道URL在不久的将来可能会改变。因此,我在寻找一种功能,它允许在整个项目中使用一个变量来代替这个URL。所以如果需要的话,它可以很容易的改变,但是我找不到。

Is there a way to achieve this?

有办法做到这一点吗?

2 个解决方案

#1


6  

By looking into javadoc specification doc I see this tag : {@value}

通过查看javadoc规范doc,我看到了这个标签:{@value}

Displays the value of a constant, which must be a static field.

显示一个常量的值,它必须是一个静态字段。

So if you create a class for example DocLinksHolder and declare static fields there, then you can refer to them in javadoc.

因此,如果您创建一个类,例如DocLinksHolder,并在那里声明静态字段,那么您可以在javadoc中引用它们。

{@value DocLinksHolder#fieldName}

#2


1  

If you are using maven, you can use its filtering feature.

如果您正在使用maven,您可以使用它的过滤特性。

With this in your pom :

在你的pom中:

<resources>
  <resource>
    <directory>src/main/java</directory>
    <filtering>true</filtering>
  </resource>
</resources>

Maven will find all string which match ${something} and replace them with values coming from your pom.

Maven将找到所有匹配${something}的字符串,并用来自pom的值替换它们。

For example, you can put

例如,你可以

/**
 * URL is ${url}.
 */

and in your pom :

在你的pom中:

<properties>
  <url>myUrl.com</url>
</properties> 

#1


6  

By looking into javadoc specification doc I see this tag : {@value}

通过查看javadoc规范doc,我看到了这个标签:{@value}

Displays the value of a constant, which must be a static field.

显示一个常量的值,它必须是一个静态字段。

So if you create a class for example DocLinksHolder and declare static fields there, then you can refer to them in javadoc.

因此,如果您创建一个类,例如DocLinksHolder,并在那里声明静态字段,那么您可以在javadoc中引用它们。

{@value DocLinksHolder#fieldName}

#2


1  

If you are using maven, you can use its filtering feature.

如果您正在使用maven,您可以使用它的过滤特性。

With this in your pom :

在你的pom中:

<resources>
  <resource>
    <directory>src/main/java</directory>
    <filtering>true</filtering>
  </resource>
</resources>

Maven will find all string which match ${something} and replace them with values coming from your pom.

Maven将找到所有匹配${something}的字符串,并用来自pom的值替换它们。

For example, you can put

例如,你可以

/**
 * URL is ${url}.
 */

and in your pom :

在你的pom中:

<properties>
  <url>myUrl.com</url>
</properties>