查看jar包内容

查看jar包内容

查看jar包内容的基本命令:

jar tf jar-file

参数解释:

  • The t option indicates that you want to view the table of contents of the JAR file.
  • The f option indicates that the JAR file whose contents are to be viewed is specified on the command line.
  • The jar-file argument is the path and name of the JAR file whose contents you want to view.

The t and f options can appear in either order, but there must not be any space between them.

This command will display the JAR file‘s table of contents to stdout.

You can optionally add the verbose option, v, to produce additional information about file sizes and last-modified dates in the output.

案例

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

use the v option:

jar tvf TicTacToe.jar
    68 Thu Nov 01 20:00:40 PDT 2012 META-INF/MANIFEST.MF
   553 Mon Sep 24 21:57:48 PDT 2012 TicTacToe.class
  3708 Mon Sep 24 21:57:48 PDT 2012 TicTacToe.class
  9584 Mon Sep 24 21:57:48 PDT 2012 TicTacToe.java
     0 Mon Sep 24 21:57:48 PDT 2012 audio/
  4032 Mon Sep 24 21:57:48 PDT 2012 audio/beep.au
  2566 Mon Sep 24 21:57:48 PDT 2012 audio/ding.au
  6558 Mon Sep 24 21:57:48 PDT 2012 audio/return.au
  7834 Mon Sep 24 21:57:48 PDT 2012 audio/yahoo1.au
  7463 Mon Sep 24 21:57:48 PDT 2012 audio/yahoo2.au
   424 Mon Sep 24 21:57:48 PDT 2012 example1.html
     0 Mon Sep 24 21:57:48 PDT 2012 images/
   157 Mon Sep 24 21:57:48 PDT 2012 images/cross.gif
   158 Mon Sep 24 21:57:48 PDT 2012 images/not.gif

The JAR file contains the TicTacToe class file and the audio and images directory, as expected.

The output also shows that the JAR file contains a default manifest file, META-INF/MANIFEST.MF, which was automatically placed in the archive by the JAR tool.。

All pathnames are displayed with forward slashes, regardless of the platform or operating system you‘re using. Paths in JAR files are always relative;

1.1对 Manifest的解释

官方说明:

When you create a JAR file, it automatically receives a default manifest file. There can be only one manifest file in an archive, and it always has the pathname

META-INF/MANIFEST.MF

When you create a JAR file, the default manifest file simply contains the following:

Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)

These lines show that a manifest‘s entries take the form of "header: value" pairs. The name of a header is separated from its value by a colon. The default manifest conforms to version 1.0 of the manifest specification and was created by the 1.7.0_06 version of the JDK.

The manifest can also contain information about the other files that are packaged in the archive. Exactly what file information should be recorded in the manifest depends on how you intend to use the JAR file. The default manifest makes no assumptions about what information it should record about other files.

Digest information is not included in the default manifest.

中文详解:

JAR包的描述信息、启动时的配置信息和安全性信息等均保存在META-INF下

META-INF/MAINFEST.MF清单文件组成元素                

META-INF/MAINFEST.MF清单文件由1个 main-section 和0到N个 individual-section 组成,而每个section中含有多个attribute组成,其中 main-section 中的attribute命名为 main-attribute ,而 individual-section 中的attribute命名为 perentry-attribute 。

各个attribute间使用<CR><LF>作为分隔符(Unix下则使用<LF>作为分隔符,Mac下则使用<CR>作为分隔符)。

individual-section 以名为 Name 的 perentry-attribute 来标识该区域,且作为该区域的起始行。

示例:

Manifest-Version: 1.0
Created-By: 1.2 (Sun Microsystems Inc.)
Sealed: true
Name: foo/bar/
Sealed: false

main-section 用于描述JAR包的安全、配置信息,和对JAR包内所有包和文件的默认信息。

每个individual-section 用于描述JAR包中单个包或文件,但不是JAR包中的每个包和文件都必须配置 individual-section ,但对于需要被签名的文件就必须配置对应的 individual-section 了。

1.1.1、main-attribute 详解

1. 常规属性

Mainfest-Version: JAR版本号
Created-By: 生产者
Signature-Version: 签名版本
Class-Path: 依赖项列表,若存在多个依赖项时则采用空格分隔。依赖项路径为以JAR包路径为参考系的相对路径

2. 可执行的JAR包属性

Main-Class: main函数所在的全限定类名

1.1.2、 perentry-attribute 详解

1. Name属性, individual-section 的起始属性,包命名规范形如:com/test/myapp/,文件命名规范形如:com/test/myapp/MyApp.class。

2. 定义文件内容

Content-Type: MIME类型(格式为:type/subtype。例如,image/jpeg)

1.1.3、注意事项                              

1. 键值对独立占据一行或多行;

2. 每行最大长度为72个字符;

3. 每行的最后一个字符必须以回车符换行符结尾,而且回车符换行符不能有空格(使用正则表达式表达每行规范就是/^.+\S\r\n$/);

4. 若键值对独立占据多行,那么从第二行起,必须以一个或以上的空格开头(使用正则表达式表达第二行及其余行的规范就是/^[ ]{1,}.+\S\r\n$/)。

原文地址:https://www.cnblogs.com/wqbin/p/11128391.html

时间: 2025-01-14 17:10:38

查看jar包内容的相关文章

如何查看 JAR 包的源代码

原文同步至 http://www.waylau.com/watch-source-code-in-jar/ Java 项目的编译文件经常被打包成 JAR(Java Archive,Java 归档文件)文件,当然,作为学习,有时候也非常想看到这个 JAR 被打包前的源代码是怎么样的. 下面提供几种查看 JAR 包的源代码方式. 环境 JDK 7+ Maven 3.2.x Eclipse 4.x Maven 项目 ,如下图设置后,直接双击 要查看的 .class 文件即可,它会自动下载源文件,这样就

Maven查看JAR包的依赖关系

如果是用命令行,可进入项目所在目录,然后输入: mvn dependency:tree ,来查看jar包依赖关系. 另外还可以在eclipse操作,如下图所示: 点击run后,开始输出JAR包依赖树. 我在执行这步的时候报了下面的异常: Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.graph.DependencyNode 在网上搜了好多地方都没有类似的错误,后来参考了一些帖子,怀疑是maven-dependen

如何查看jar包的版本号?

jar包根目录里的META-INF目录下的MANIFEST.MF文件里一般有会记录版本信息,可以到这个文件里查看   打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录,这个目录下会有一些文件,其中必有一个MANIFEST.MF,这个文件描述了该Jar文件的很多信息,下面将详细介绍MANIFEST.MF文件的内容,先来看struts.jar中包含的MANIFEST.MF文件内容: Manifest-Version: 1.0 Created-By: Apache Ant

Eclipse 无法查看jar包文件源代码解决方法

1.打开第三方依赖包,源文件的快捷键:ctrl + mouseClick 2.由于我们下载的第三方jar 包,如Spring等相关的依赖包时,并没有附加下载相应的源文件,所以经常出现如图的这种问题. 解决方法如下: 1.jar包下都为编译生成的 .class 文件,所以安装相应的反编译插件,反编译为 .java 文件后,即可查看源码. 2.先下载jadClipse的jar包(反编译插件) 链接:sourceforge.net/projects/jadclipse/ 3.然后,将net.sf.ja

查看jar包的jdk版本并降级

用解压工具打开jar包(例子都是用7zip) 进入到META-INF目录,查看MANIFEST.MF文件,查看Bulid-Jdk,下图就为1.7.0_55版本的JDK,这就表示jetty-servlet-9.2.0.RC0.jar这个jar包的JDK版本是1.7的 当发现jar包的jdk版本为1.8,而linux的JDK版本为1.7,那么需要找到一个jdk为1.7版本的jar包,这就需要去到maven中央仓库去找到一个合适的jar包 如jetty-servlet-9.3.4.RC0.jar的JD

java进阶(六)------源码学习---myeclipse如何查看jar包的源码

查看源码的思路和代码规范是我们学习完善代码编写能力的重要手段. 有时候我们会遇到想看某个jar包中的类和方法的实现,但是无法查看. 这是因为未加载jar包的源码.只要找到jar包的源码并把路径设置好 就可以查看了. 源码下载 源码的下载 需要自己按照版本找好,可以是zip也可以是jar包. 这里有几个找源码的网站,也可以去jar包的官网查找. github https://github.com/openjdk-mirror/jdk7u-jdk sourceforge https://source

Eclipse中如何快速查看jar包中 的class源码

我们查看jar源码时,一般是安装个jd-gui,把jar拷出来,然后从jd-gui中打开jar再查看源码,这个过程不免有些麻烦,当然,本篇所讲的快速查看的方法也没什么高科技手段,只是将jd-gui集成在Eclipse中,然后就可以在Eclipse中直接打开class了,这样会不但操作方便也会节省不少时间,具体步骤: 下载插件:jd-eclipse-site-1.0.0-RC2.zip 打开Eclipse-->Help-->Install New Software: 在Name框中命名,然后点击

(转)Eclipse中查看jar包中的源码

Java Decompiler Plugin For Eclipse IDE 1. 下载JAD ,  1.5.8版本的jad在 http://www.softpedia.com/progDownload/JAD-Download-85911.html 将展开后的jad.exe放到某个目录,例如 c:/jad/jad.exe 2. 下载JADClipse插件 http://sourceforge.net/projects/jadclipse/files/ 将展开后的net.sf.jadclipse

eclipse查看jar包中class的中文注释乱码问题的解决

1,问题来源是在eclipse中直接查看springside的class(由eclipse自动反编译)里面注释的乱码问题: Preferences-General-Workspace-Text file encoding 设置为uft-8 最后重启一下eclipse通常就ok了. 2,若是关联jar的源码出现乱码,则使用以下方法尝试: 将Eclipse的Preferences中的General>ContentTypes中的Java Class File和Text的default encoding