0

So I am using this plugin for generating javadocs:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

and to generate the docs I use: mvn javadoc:javadoc

and I get something like this:

enter image description here

I have two questions:

  1. Is there a way to put an <a> or <div> in the html sections so that I can hyperlink to it using this technique? https://stackoverflow.com/a/2835151/1223975

  2. I need to include a javascript tag in each html file for the generated javadocs. Is there a way to tell the plugin to include this script tag in each html file? In the <head>? Or really anywhere since it's for styling.

For example, to solve #2, I tried adding this above each class in my project:

/*
 * <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
 **/
public class Foo {}

but that didn't seem to work, the script tag doesn't get added to the html.

  • Here's a link to the javadoc plugin documentation: https://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html –  Feb 18 '19 at 01:00

2 Answers2

0

In order to solve #2, I just did a hack. I copied the source from the google-code-prettify library to a shared .js file that is already loaded by javadoc pages.

https://rawgit.com/google/code-prettify/master/loader/run_prettify.js

I copied the above code from the link into a .js file into target/site/apidocs/script.js. This isn't a great solution if the javadoc format changes but will work for now. I'd prefer to be able to declaratively load <script> tags at will in my javadoc comments if possible.

0

I figured out #2, so my syntax was wrong, instead of this:

/*
 * <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
 **/
public class Foo {}

should be:

/**
 * <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
 */
public class Foo {}

then it will load the script it whatever page of the javadocs you are on.