查看jar包内容

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

  1. 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.

案例

  1. jar tf TicTacToe.jar
  2. META-INF/MANIFEST.MF
  3. TicTacToe.class
  4. audio/
  5. audio/beep.au
  6. audio/ding.au
  7. audio/return.au
  8. audio/yahoo1.au
  9. audio/yahoo2.au
  10. images/
  11. images/cross.gif
  12. images/not.gif

use the v option:

  1. jar tvf TicTacToe.jar
  2. Thu Nov :: PDT META-INF/MANIFEST.MF
  3. Mon Sep :: PDT TicTacToe.class
  4. Mon Sep :: PDT TicTacToe.class
  5. Mon Sep :: PDT TicTacToe.java
  6. Mon Sep :: PDT audio/
  7. Mon Sep :: PDT audio/beep.au
  8. Mon Sep :: PDT audio/ding.au
  9. Mon Sep :: PDT audio/return.au
  10. Mon Sep :: PDT audio/yahoo1.au
  11. Mon Sep :: PDT audio/yahoo2.au
  12. Mon Sep :: PDT example1.html
  13. Mon Sep :: PDT images/
  14. Mon Sep :: PDT images/cross.gif
  15. Mon Sep :: PDT 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

  1. META-INF/MANIFEST.MF

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

  1. Manifest-Version: 1.0
  2. 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 来标识该区域,且作为该区域的起始行。

示例:

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

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

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

1.1.1、main-attribute 详解

1. 常规属性

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

2. 可执行的JAR包属性

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

1.1.2、 perentry-attribute 详解

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

2. 定义文件内容

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

1.1.3、注意事项                              

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

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

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

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

查看jar包内容的更多相关文章

  1. [Linux] 查看jar包内容

    jar vtf  fileName.jar 用法: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] file ...

  2. (原创) Maven查看JAR包的依赖关系

    如果是用命令行,可进入项目所在目录,然后输入: mvn dependency:tree ,来查看jar包依赖关系. 另外还可以在eclipse操作,如下图所示: 点击run后,开始输出JAR包依赖树. ...

  3. java反射查看jar包中所有的类名方法名

    不反编译,不用其他工具,用java反射查看jar包中所有的类名方法名,网上很多都报错,下面这个你试试看:话不多说直接撸代码: import java.lang.reflect.Field; impor ...

  4. 如何查看 JAR 包的源代码

    ava 项目的编译文件经常被打包成 JAR(Java Archive,Java 归档文件)文件,当然,作为学习,有时候也非常想看到这个 JAR 被打包前的源代码是怎么样的. 下面提供几种查看 JAR ...

  5. SpringBoot小技巧:修改java可执行jar包内容

    SpringBoot小技巧:修改java可执行jar包内容 情景描述 在生产环境中,有时候我们发现了个小bug,开发迅速修改代码后,很多时候我们不得不重新发布一个新的可执行jar包上去替换掉.但是这样 ...

  6. 怎么查看jar包版本

    jar包根目录里的META-INF目录下的MANIFEST.MF文件里一般有会记录版本信息,可以到这个文件里查看 打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录,这个目录 ...

  7. 如何查看jar包的版本号?

    jar包根目录里的META-INF目录下的MANIFEST.MF文件里一般有会记录版本信息,可以到这个文件里查看   打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录,这个 ...

  8. 如何查看jar包的版本号?(转)

    转自 : http://www.cnblogs.com/wych/p/4072913.html jar包根目录里的META-INF目录下的MANIFEST.MF文件里一般有会记录版本信息,可以到这个文 ...

  9. 【转】Eclipse中查看jar包中的源码

    (简单的方式:通过jd-gui来进行反编译,最简单!,参考我的另一篇博文, 地址:http://www.cnblogs.com/gmq-sh/p/4277991.html) Java Decompil ...

随机推荐

  1. Jenkins安装以及配置

    Jenkins介绍 Jenkins是一个java开发的.开源的.非常好用持续集成的工具,它能帮我们实现自动化部署环境.测试.打包等等的工作,还可以在构建任务成功或者失败之后给我们发邮件通知. 什么叫持 ...

  2. Jmeter之内存溢出解决办法

    使用Jmeter进行压力测试会遇到一段时间后报内存溢出的错误,导致Jmeter卡死.这是因为Jmeter默认的HEAP配置的太小了,解决办法如下: 1.Windows环境   修改jmeter.bat ...

  3. Selenium学习之==>Selenium介绍

    前世 Selenium RC 早期的Selenium使用的是JavaScript注入技术与浏览器打交道,需要Selenium RC启动一个Server,将操作Web元素的API调用转化为一段段Java ...

  4. Mysql登录报1045错误

    MySQL在使用root密码登陆报 1045 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password ...

  5. 【HBase】五、HBase的Java接口

      HBase是Hadoop中的一个重要组件,自然也是基于Java语言开发的,因此HBase有很好的Java接口供程序员调用,通过一个例子来演示java如何使用HBase数据库.   要想在HBase ...

  6. 手工设计神经MNIST使分类精度达到98%以上

    设计了两个隐藏层,激活函数是tanh,使用Adam优化算法,学习率随着epoch的增大而调低 import tensorflow as tf from tensorflow.examples.tuto ...

  7. 【windows】windows安全基础

    windows安全基础 安全主体 security principal 是可以进行身份验证的实体. 哪个安全主体在要求访问?这个维度可以是用户,计算机和进程.一旦确认以后,系统就会发放SID. 例子: ...

  8. 简述Vue项目中返回上一页

    1.背景 由于Vue所生成的项目叫做单页应用,即SPA,如果还是使用jQuery中的go(-)或back()是行不通的,所以,我们使用到了Vue中的编程式导航. 2.基本使用 定义返回按钮: < ...

  9. vscode打开SpringBoot项目

    1.使用vscode打开java项目所在文件夹 2.按ctl+~ 打开命令面板 mvn -Dmaven.test.skip=true spring-boot:run

  10. [转帖] 百度百科 sino

    sino https://baike.baidu.com/item/sino/2830?fr=aladdin 百度百科 sinograin 中储粮 (组合词前缀) 编辑 讨论 Sino,就是「中国.东 ...