Updating a JAR File

本文介绍如何使用Jartool的-u选项更新现有JAR文件的内容,包括修改清单或添加文件。提供基本命令格式及示例。

The Jar tool provides a u option which you can use to update the contents of an existing JAR file by modifying its manifest or by adding files.

The basic command for adding files has this format:

jar uf jar-file input-file(s)

In this command:

  • The u option indicates that you want to update an existing JAR file.
  • The f option indicates that the JAR file to update is specified on the command line.
  • jar-file is the existing JAR file that is to be updated.
  • input-file(s) is a space-delimited list of one or more files that you want to add to the JAR file.

Any files already in the archive having the same pathname as a file being added will be overwritten.

When creating a new JAR file, you can optionally use the -C option to indicate a change of directory. For more information, see the Creating a JAR File section.

Examples

Recall that TicTacToe.jar has these contents:

META-INF/MANIFEST.MF
TicTacToe.class
TicTacToe.class
TicTacToe.java
audio/
audio/beep.au
audio/ding.au
audio/return.au
audio/yahoo1.au
audio/yahoo2.au
example1.html
images/
images/cross.gif
images/not.gif

Suppose that you want to add the file images/new.gif to the JAR file. You could accomplish that by issuing this command from the parent directory of the images directory:

jar uf TicTacToe.jar images/new.gif

The revised JAR file would have this table of contents:

META-INF/MANIFEST.MF
TicTacToe.class
TicTacToe.class
TicTacToe.java
audio/
audio/beep.au
audio/ding.au
audio/return.au
audio/yahoo1.au
audio/yahoo2.au
example1.html
images/
images/cross.gif
images/not.gif
images/new.gif

You can use the -C option to "change directories" during execution of the command. For example:

jar uf TicTacToe.jar -C images new.gif

This command would change to the images directory before adding new.gif to the JAR file. The images directory would not be included in the pathname of new.gif when it's added to the archive, resulting in a table of contents that looks like this:

META-INF/MANIFEST.MF
META-INF/MANIFEST.MF
TicTacToe.class
TicTacToe.class
TicTacToe.java
audio/
audio/beep.au
audio/ding.au
audio/return.au
audio/yahoo1.au
audio/yahoo2.au
example1.html
images/
images/cross.gif
images/not.gif
new.gif

### 如何使用 WinSCP 更新服务器上的 JAR 文件 为了确保能够高效且安全地更新服务器上的 JAR 文件,可以采用批处理脚本来自动化这一过程。下面提供了一个详细的解决方案。 #### 准备工作 确保本地计算机已安装并配置好 WinSCP 客户端,并拥有访问目标 Linux 服务器的有效凭证[^1]。 #### 创建批处理文件 (UpdateJar.bat) 创建一个新的 `.bat` 批处理文件用于执行以下命令: ```batch @echo off set WINSCP_PATH="C:\Program Files (x86)\WinSCP\WinSCP.com" set LOCAL_JAR_PATH="D:\path_to_your_jar_file\yourfile.jar" set SERVER_ADDRESS=server_ip_or_hostname set SERVER_USERNAME=username set SERVER_PASSWORD=password set REMOTE_DIR=/remote/path/to/jar/ rem Connect to the server and upload jar file "%WINSCP_PATH%" /command ^ "open sftp://%SERVER_USERNAME%:%SERVER_PASSWORD%@%SERVER_ADDRESS%/ -hostkey=""ssh-rsa xxx""" ^ "lcd %LOCAL_JAR_PATH%" ^ "cd %REMOTE_DIR%" ^ "put yourfile.jar" ^ "exit" if errorlevel 1 ( echo Error updating JAR on remote server. exit /b %errorlevel% ) echo Successfully updated JAR on remote server. pause ``` 此脚本会自动连接到指定地址的 SFTP 服务,切换至远程目录并将新的 JAR 文件上载替换旧版本[^3]。 #### 自动重启应用容器(可选) 如果有 Docker 部署,则可以在上述脚本之后加入调用 `deploy.sh` 脚本的部分来重新启动应用程序容器: ```bash #!/bin/bash sudo docker-compose down && sudo docker-compose up -d --build ``` 这一步骤确保每次更新后都能立即生效新版本的应用程序逻辑。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值