Linux command
jar 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Create JAR file
jar cf [output.jar] [files...]
Create with manifest
jar cfm [output.jar] [MANIFEST.MF] [files...]
Extract JAR file
jar xf [archive.jar]
List contents
jar tf [archive.jar]
Create executable JAR
jar cfe [output.jar] [MainClass] [files...]
Update JAR file
jar uf [archive.jar] [newfiles...]
Extract specific file
jar xf [archive.jar] [path/to/file]
List contents verbosely
jar tvf [archive.jar]
Create JAR from directory
jar cf [output.jar] -C [build/classes] .
说明
jar is the Java Archive tool. It packages Java class files, resources, and metadata into a single JAR file for distribution and deployment. JAR files use ZIP format with a manifest (META-INF/MANIFEST.MF) containing metadata. Executable JARs specify a main class in the manifest.
参数
- c
- Create new archive.
- x
- Extract archive.
- t
- List table of contents.
- u
- Update existing archive.
- f _file_
- Specify archive filename.
- m _manifest_
- Include manifest file.
- e _class_
- Set entry point (main class).
- v
- Verbose output.
- 0
- Store only (no compression).
- M
- Do not create a manifest file.
- i
- Generate index information for specified JAR files.
- C _dir_
- Change to directory before including the following files.
- --release _VERSION_
- (Java 9+) Place following files in a versioned directory for multi-release JARs.
FAQ
What is the jar command used for?
jar is the Java Archive tool. It packages Java class files, resources, and metadata into a single JAR file for distribution and deployment. JAR files use ZIP format with a manifest (META-INF/MANIFEST.MF) containing metadata. Executable JARs specify a main class in the manifest.
How do I run a basic jar example?
Run `jar cf [output.jar] [files...]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does c do in jar?
Create new archive.