I have just started to generate javadoc and ultimately learn that there is a proper directory for this in the target folder and these documents can be generated via maven command.
The question about this issue is that, I am using maven pluging to generate javadoc. In this case, I am not sure if I need to generate javadoc for the production environment. So;
1- As I already annotate my methods, classes for javadoc generation, do I need to generate javadoc before I need to use or customer needs to use on production phase?
2- If a customer wants to generate javadoc on production phase, how should I provide javadoc or javadoc generate feature in a Docker container? I thought to run the following command on my corresponding Dockerfile, but ı am not sure if I also need to copy this any folder during Docker build?
Dockerfile:
FROM maven:3.8.1-openjdk-17-slim AS builder
USER demo
WORKDIR /app
COPY pom.xml ./
COPY src ./src
RUN mvn clean install -Dmaven.test.skip=true
// ---> should I add this line and then copy command?
RUN mvn javadoc:javadoc
...
2
Answers
Javadoc is technical documentation, generated during the build phase of your project.
By default, you’ll get html files generated in the target folder.
You say your customer wants "access". Do they want to access these files via a web browser? In that case you’ll need to make sure that a web server serves these files. I’d suggest you create another Docker container containing a static web server (like nginx) and copy the javadoc files to the right location.
Your end users using this Docker setup and your downstream users that could use Javadoc are probably different users. I would not try to generate Javadoc in a Dockerfile.
Approximately the only thing you can do with a built Docker image is run it. The Dockerfile can only generate content in that image; it can’t generate files on the host system, and it’s not really the right point to export data to another source. If you had the image you could
without knowing that it had Java inside it, but you’d have to do extra Docker-specific things to extract a jar file or Javadocs.
If someone was going to use the Javadoc output, they’d need a copy of the jar file on their classpath. You could in principle extract the jar file out of an image, but a more typical path would be to publish it to somewhere like Maven Central. I’d expect a consumer of this path to be a programmer who knows what a Java class is, and isn’t just trying to run a prepackaged application. You wouldn’t want to package the HTML-format developer-oriented documentation inside the opaque end-user-runnable Docker artifact.
Many Java Dockerfiles just
COPY
a jar file into the image; this works well for Java in particular since the jar and class file formats are designed to be portable. I could imagine a CI system running steps like