0

I wrote custom Doclet implementation and I run it with Maven javadoc:

<build>
  <resources>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <filtering>false</filtering>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <optimize>true</optimize>
                    <debug>true</debug>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <doclet>custom.doc.CustomDoclet</doclet>
                    <docletArtifact>
                        <groupId>custom.doc</groupId>
                        <artifactId>custom-doc</artifactId>
                        <version>1.0.0-SNAPSHOT</version>
                    </docletArtifact>
                    <useStandardDocletOptions>false</useStandardDocletOptions>
                    <destDir>custom-doc</destDir>
                </configuration>
            </plugin>
        </plugins>
    </build>

In customDoclet class I have following lines:

public class CustomDoclet extends Doclet {

    public static boolean start(RootDoc root) {
        (1) System.out.println(Thread.currentThread().getContextClassLoader().getResource(".")); // returns null

        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.init();

        (2) Template template = velocityEngine.getTemplate("template/html_template.vm"); // no such file exception thrown

        return true;
    }

}

(1) line returns null, and (2) throws execption during javadoc phase.

How can I use resource file?

In jar with CustomDoclet there is file 'template/hmtl_template.vm' in the root.

Kamil Z
  • 30
  • 1
  • 5
  • If there is a `FileNotFoundException` then probably there is no such file where your code expects it to be. Try the full path to verify. Then find out what your working directory is and where your relative path leads to. See that it's not the path you are expecting. Change it accordingly. – Ben Jun 14 '18 at 07:09
  • Thank you for answer. Setting these properties helped: `velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");` `velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());` `velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");` – Kamil Z Jun 14 '18 at 07:29

0 Answers0