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.
Is there a way to achieve this?
Writing Javadoc Comments In general, Javadoc comments are any multi-line comments (" /** ... */ ") that are placed before class, field, or method declarations. They must begin with a slash and two stars, and they can include special tags to describe characteristics like method parameters or return values.
In order to create a Javadoc comment, place the cursor before a class declaration, a method, or a variable declaration. Then, add a comment. A Javadoc comment starts with a slash and two asterisks, and you can create it easily by typing those characters, slash, asterisk, asterisk, and then pressing enter or return.
This is a documentation comment and in general its called doc comment. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.
General FormattingA Javadoc comment is written in HTML and can therefore use common HTML tags. A JavaDoc comment is made up of two parts, the description followed by block tags. Keep in mind that Javadoc is often read in it's source form, so it should be easy to read and understand without the generated web frontend.
By looking into javadoc specification doc I see this tag : {@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.
{@value DocLinksHolder#fieldName}
If you are using maven, you can use its filtering feature.
With this in your 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.
For example, you can put
/**
* URL is ${url}.
*/
and in your pom :
<properties>
<url>myUrl.com</url>
</properties>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With