admin管理员组

文章数量:1122832

I have a working spring boot app executing from a jar that exposes a REST API, which is documented with springdoc/openapi/swagger by exposing on my spring boot app, too.

I can create the javadoc jar with maven, and I'd like to expose those javadocs with my spring boot app. I am able to do so if I manually unzip the jar into a directory like /static which spring boot puts into its executable jar. No problems.

But I'd like to skip the manual unzip and just use the javadoc.jar itself. However, if I do that, an http browser request will just download the jarfile, which is undesirable.

I know that Java is designed to easily read a jar file without unzipping it by setting the classpath to the jar file. It seems that spring might have a bean for effectively reading websites inside a jar, like what javadoc makes.

What I would like is for the user to enter http://localhost:8080/myapp/javadoc/index.html and spring boot would get the index.html out of /static/javadoc.jar, directly without unzipping... is that possible?

I have a working spring boot app executing from a jar that exposes a REST API, which is documented with springdoc/openapi/swagger by exposing on my spring boot app, too.

I can create the javadoc jar with maven, and I'd like to expose those javadocs with my spring boot app. I am able to do so if I manually unzip the jar into a directory like /static which spring boot puts into its executable jar. No problems.

But I'd like to skip the manual unzip and just use the javadoc.jar itself. However, if I do that, an http browser request will just download the jarfile, which is undesirable.

I know that Java is designed to easily read a jar file without unzipping it by setting the classpath to the jar file. It seems that spring might have a bean for effectively reading websites inside a jar, like what javadoc makes.

What I would like is for the user to enter http://localhost:8080/myapp/javadoc/index.html and spring boot would get the index.html out of /static/javadoc.jar, directly without unzipping... is that possible?

Share Improve this question asked Nov 22, 2024 at 21:04 jtalicsjtalics 1032 silver badges6 bronze badges 1
  • 1 Most performant way would be to include static generation of java doc during build time as maven build step and package/dockerize it, and then expose an api to read the statically generated content. Every version will generate and overwrite the static file. – zookastos Commented Nov 24, 2024 at 4:47
Add a comment  | 

1 Answer 1

Reset to default 1

You can distribute Javadocs file directly from a .jar in your Spring Boot app by developing a custom controller that can use the JarFile API to read and run files dynamically without unzipping. This helps you to access Javadoc files through URLs like /myapp/javadoc/index.html, making sure a clean and structured solution customized to your needs.. Optional Optimizations Cache Javadoc Files: If you expect high traffic, you can extract the Javadoc files into a temporary directory on startup and serve them from there for better performance. Add Security Filters: Validate the filePath parameter to avoid directory traversal attacks or unauthorized access to other files in the

本文标签: javaPossible for Spring Boot to serve javadocs without unzipping javadocjar manuallyStack Overflow