[英]Deployed spring boot jar file to Docker - how to access and change static resources
I'm kinda new to spring and web development as a whole.我对 spring 和 web 整体开发有点陌生。
My question is:我的问题是:
When you build a spring boot project (using Maven) into jar file and deploy it via Docker, everything is in one jar file. When you build a spring boot project (using Maven) into jar file and deploy it via Docker, everything is in one jar file. How can you access your resources (css, js, images, html...) if you want to edit something?如果您想编辑某些内容,如何访问您的资源(css、js、图像、html...)? Like change something in css file or add something to html page.就像在 css 文件中更改某些内容或在 html 页面中添加一些内容一样。 Is it even possible?甚至可能吗? Or do you have to build a new jar file everytime, when you need to change something (in frontend)?或者,当您需要更改某些内容(在前端)时,您是否必须每次都构建一个新的 jar 文件? Also, when there are being uploaded some images or other files, where are they stored?另外,当上传一些图像或其他文件时,它们存储在哪里? This stuff is very confusing for me and i can't find any related books or help at all.这些东西让我很困惑,我根本找不到任何相关的书籍或帮助。
Thanks for help!感谢帮助!
when you package any java program it is nothing but a zip file.当您使用 package 任何 java 程序时,它只不过是一个 zip 文件。 Based on what kind of package it is, you wither name it as a Jar or War.根据它是哪种package,您将其命名为Jar或War。
Jar == Java archive
War == Web archive
Now, given the fact that jar
and war
both are essentially a zip archive, it gives you flexibility to extract and modify them just like any other zip file.现在,鉴于jar
和war
本质上都是 zip 存档,它使您可以像任何其他 zip 文件一样灵活地提取和修改它们。
On windows, I think softwares like 7zip let you update the jar inline.在 windows 上,我认为像 7zip 这样的软件可以让您更新 jar 内联。 I have done it multiple times, especially when I wanted to change application.properties
alone on cloud machines, and no other code changes were required.我已经做过很多次了,尤其是当我想在云机器上单独更改application.properties
时,不需要更改其他代码。 In such cases, building the whole jar and transferring it again to cloud machine could be time consuming.在这种情况下,构建整个 jar 并将其再次传输到云机器可能会很耗时。 So I would just extract the contents, update whatever I want to, and rezip the package.所以我只需提取内容,更新我想要的任何内容,然后重新压缩 package。
Here is the commands you can use - 这是您可以使用的命令 -
jar xf jar-file
This should extract the files into a directory.这应该将文件提取到一个目录中。
This SO thread will guide you towards creating jar files.此SO 线程将指导您创建 jar 文件。
Something like jar cf myJar.jar **
should be enough to generate a jar file IMO, but syntax might vary.像jar cf myJar.jar **
之类的东西应该足以生成 jar 文件 IMO,但语法可能会有所不同。
The jar file is actually just a zip file containing all the files and classes of your application, so technically you can change files in it like any other zip archive. jar 文件实际上只是一个 zip 文件,其中包含应用程序的所有文件和类,因此从技术上讲,您可以像任何其他 zip 存档一样更改其中的文件。 Best practice is to build the jar file using Maven or Gradle from source every time you need something changed.最佳实践是每次您需要更改某些内容时,使用 Maven 或 Gradle 从源代码构建 jar 文件。
It's good practice to keep the source in version control using Git, and tag each build in the git repository - that way you can easily keep track of changes to the jar file by looking at what's in git at the time of the build. It's good practice to keep the source in version control using Git, and tag each build in the git repository - that way you can easily keep track of changes to the jar file by looking at what's in git at the time of the build.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.