简体   繁体   English

已部署 spring 引导 jar 文件到 Docker - 如何访问和更改 ZA81259CEF45E959C3D9D2AC40Z 资源

[英]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.现在,鉴于jarwar本质上都是 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.

相关问题 Spring Boot static 资源在我建的 jar 但不在 jar 部署到 Docker - Spring Boot static resources are in my built jar but not in jar deployed to Docker 部署 JAR 文件后更新 spring 引导 static 资源 - Updating spring boot static resources after deploying JAR file 如何动态地将静态资源添加到spring-boot jar应用程序? - How to dynamically add static resources to spring-boot jar application? 如何在不重新部署整个胖 jar 文件的情况下对部署的 Spring 引导应用程序进行小的更改? - how to make a small change in a deployed Spring boot app without re-deploying the whole fat jar file? Spring Boot 使用 docker 为静态资源返回 404 - Spring Boot returns 404 for static resources with docker Spring 在 docker 上启动无法从资源中读取属性文件,但是可以在没有 Docker 的情况下使用 Z93F725A4jar423D21C28 - Spring boot on docker not able to read a property file from resources, but the can without Docker with java -jar 使用Spring Boot无法访问静态资源 - Can't access static resources with Spring Boot Spring boot WAR 部署到 Tomcat 并且缺少静态资源的上下文 - Spring boot WAR deployed to Tomcat and missing context for static resources Spring Boot 部署的 JAR 在部署目录中找不到属性文件 - Spring Boot deployed JAR not finding properties file in deployed directory 我在服务器上部署了带有 jar 文件的 Spring Boot 项目,但无法访问它 - I deployed my spring boot project with jar file on my server and can't access it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM