什么是 JAR?Java 存档文件格式解析

JAR(Java Archive)是Sun Microsystems的ZIP格式,用于打包Java类、资源和清单。

免费在线文件转换工具。在 Windows、macOS、Linux、Android 和 iOS 上的 Chrome、Firefox、Safari、Edge、Opera 及其他现代浏览器中运行。无需安装软件或注册。所有转换都直接在您的浏览器中进行,因此您的文件不会离开您的设备。免费使用,无需账户。

Archive

什么是 JAR?Java 存档文件格式解析

一个基于 ZIP 的包,将 Java 类、资源和元数据打包成一个文件。

最后更新:

Year1996
TypeArchive (application package)
UsageJava application packaging

What is it?

JAR, short for Java Archive, is a package file format used to aggregate many Java class files, associated metadata, and resources such as images and configuration data into a single file. It was developed by Sun Microsystems and is built on the ZIP file format.

A JAR is a ZIP archive that, by convention, contains a special META-INF directory holding a MANIFEST.MF file. The manifest records attributes such as the main class for executable JARs, classpath entries, and optional code-signing information, allowing the archive to function as a self-contained, runnable unit.

Technical Specifications

DeveloperSun Microsystems (now Oracle)
File Extension.jar
MIME Typeapplication/java-archive
Released1996 (JDK 1.1 era)
TypeZIP-based application archive

Pros & Cons

Advantages

单一可分发单元

Bundles all classes and resources into one file, simplifying deployment and distribution.

基于 ZIP 构建

Uses the well-understood ZIP format, so contents are compressed and broadly tool-compatible.

可执行且可签名

A manifest can mark a main class for direct execution, and JARs can be digitally signed for integrity.

跨平台

The same JAR runs on any platform with a compatible Java Virtual Machine.

Disadvantages

需要 JVM

JAR files cannot run without a Java runtime installed on the target system.

依赖处理

A plain JAR does not bundle external library dependencies unless built as a 'fat' or 'uber' JAR.

反编译风险

Java bytecode inside a JAR can be decompiled, so source logic is not well protected by default.

When to Use It

JAR is the standard packaging unit across the Java ecosystem.

应用程序分发

Complete Java applications are shipped as executable JARs that run via the java command.

库和依赖项

Reusable Java libraries are published as JARs and pulled in by build tools such as Maven and Gradle.

Web 和企业组件

JARs are the building blocks bundled inside WAR and EAR archives for server-side applications.

如何打开JAR文件

JAR文件通常由多种软件工具处理,这些工具可以分为专业应用程序、免费/开源选项、基于浏览器的工具和内置实用程序。专业应用程序适合需要强大功能的开发人员和企业,而免费/开源工具则吸引爱好者和预算有限的用户。基于浏览器的工具提供了无需安装的便利性,而内置实用程序为休闲用户提供基本功能。

在选择JAR文件的软件时,关键决策因素包括功能保真度、编辑与查看的需求、成本模型和平台兼容性。用户应考虑他们是否需要提取、编辑或仅查看JAR文件的内容。此外,导出能力对需要将JAR内容转换为其他格式的用户也很重要,有时将JAR转换为其他格式可能比使用特定工具更高效。

JD-GUI 1.6.6

Windows, macOS, Linux免费(GPL)

JD-GUI是一个独立的图形工具,可以显示JAR文件中的Java源代码。它允许用户反编译并查看JAR文件的结构和内容,保真度高,非常适合需要分析Java应用程序的开发人员。

主要功能
  • Java字节码的反编译
  • 查看类和方法结构
  • 类的搜索功能
  • 将源代码导出为ZIP
  • 支持Java 8及更早版本
优点
  • 高质量的反编译结果
  • 用户友好的界面
  • 跨平台可用性
局限
  • 编辑能力有限
  • 无法直接导出为其他格式

可导出为: ZIP

适合: JD-GUI非常适合需要快速高效分析和反编译JAR文件的开发人员。

访问 JD-GUI →

Eclipse IDE 2023-09

Windows, macOS, Linux免费(Eclipse公共许可证)

Eclipse IDE是一个强大的开发环境,支持Java并可以打开JAR文件进行查看和编辑。它提供了管理Java项目的工具,允许开发人员提取、修改和重新打包JAR文件,确保完整性。

主要功能
  • 集成Java开发工具
  • JAR文件的项目管理
  • 代码编辑和调试
  • 支持Maven和Gradle
  • 版本控制集成
优点
  • 全面的开发功能
  • 强大的社区支持
  • 可通过插件扩展
局限
  • 初学者学习曲线较陡
  • 与简单工具相比资源消耗较大

可导出为: JAR, WAR, EAR

适合: Eclipse IDE非常适合需要全面开发环境来处理JAR文件的专业开发人员。

访问 Eclipse IDE →

Apache Ant 1.10.12

Windows, macOS, Linux免费(Apache许可证)

Apache Ant是一个Java库和命令行工具,自动化软件构建过程,包括处理JAR文件。它允许用户通过构建脚本创建、修改和提取JAR文件,非常适合专注于自动化的开发人员。

主要功能
  • Java应用程序的构建自动化
  • 可定制的构建脚本
  • 创建和更新JAR文件
  • 依赖管理
  • 与CI/CD管道集成
优点
  • 强大的自动化能力
  • 高度可定制
  • 广泛用于企业环境
局限
  • 需要脚本知识
  • 没有图形界面

可导出为: JAR

适合: Apache Ant最适合希望在构建过程中自动化JAR文件管理的开发人员。

访问 Apache Ant →

WinRAR 6.20

Windows一次性$29.00

WinRAR是一个流行的文件归档工具,可以打开和提取JAR文件,将其视为标准归档文件。虽然它不提供编辑功能,但对于需要快速提取或压缩JAR内容的用户非常有用。

主要功能
  • 提取JAR文件
  • 压缩和归档能力
  • 支持多种归档格式
  • 归档的密码保护
  • 多卷归档支持
优点
  • 快速提取速度
  • 用户友好的界面
  • 支持多种归档格式
局限
  • 仅限于提取
  • 试用期后为付费软件

可导出为: ZIP, RAR, 7Z

适合: WinRAR适合需要可靠工具来提取JAR文件而不需要编辑的用户。

访问 WinRAR →

Convert JAR Files Free

Use our free online archive converter to convert JAR and other formats - no signup, no watermarks.

Try Archive Converter Free

References

  1. JAR File Overview - Oracle Java Documentation
  2. JAR (file format) - Wikipedia
  3. application/java-archive - IANA