`
kanpiaoxue
  • 浏览: 1781508 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

jar的用法:压缩、解压

 
阅读更多

 

解压 hello.jar

jar -xvf hello.jar    (所有jar的文件会解压到当前的目录,而不会自动创建hello的文件夹)

 

用法: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
选项:
    -c  创建新档案
    -t  列出档案目录
    -x  从档案中提取指定的 (或所有) 文件
    -u  更新现有档案
    -v  在标准输出中生成详细输出
    -f  指定档案文件名
    -m  包含指定清单文件中的清单信息
    -n  创建新档案后执行 Pack200 规范化
    -e  为捆绑到可执行 jar 文件的独立应用程序
        指定应用程序入口点
    -0  仅存储; 不使用任何 ZIP 压缩
    -P  保留文件名中的前导 '/' (绝对路径) 和 ".." (父目录) 组件
    -M  不创建条目的清单文件
    -i  为指定的 jar 文件生成索引信息
    -C  更改为指定的目录并包含以下文件
如果任何文件为目录, 则对其进行递归处理。
清单文件名, 档案文件名和入口点名称的指定顺序
与 'm', 'f' 和 'e' 标记的指定顺序相同。

示例 1: 将两个类文件归档到一个名为 classes.jar 的档案中:
       jar cvf classes.jar Foo.class Bar.class
示例 2: 使用现有的清单文件 'mymanifest' 并
           将 foo/ 目录中的所有文件归档到 'classes.jar' 中:
       jar cvfm classes.jar mymanifest -C foo/ .




==============================================[jar man start 2017-12-01 10:05]===============================================
NAME
       jar - Java archive tool

SYNOPSIS
       Create jar file
       jar c[v0M]f jarfile [ -C dir ] inputfiles [ -Joption ]
       jar c[v0]mf manifest jarfile [ -C dir ] inputfiles [ -Joption ]
       jar c[v0M] [ -C dir ] inputfiles [ -Joption ]
       jar c[v0]m manifest [ -C dir ] inputfiles [ -Joption ]

       Update jar file
       jar u[v0M]f jarfile [ -C dir ] inputfiles [ -Joption ]
       jar u[v0]mf manifest jarfile [ -C dir ] inputfiles [ -Joption ]
       jar u[v0M] [ -C dir ] inputfiles [ -Joption ]
       jar u[v0]m manifest [ -C dir ] inputfiles [ -Joption ]

       Extract jar file
       jar x[v]f jarfile [ inputfiles ] [ -Joption ]
       jar x[v] [ inputfiles ] [ -Joption ]

       List table of contents of jar file
       jar t[v]f jarfile [ inputfiles ] [ -Joption ]
       jar t[v] [ inputfiles ] [ -Joption ]

       Add index to jar file
       jar i jarfile [ -Joption ]

PARAMETERS
       cuxtivOMmf     Options that control the jar command.

       jarfile        Jar  file to be created (c), updated (u), extracted (x),
                      or have its table of contents viewed (t). The  f  option
                      and filename jarfile are a pair -- if either is present,
                      they must both appear. Note that omitting f and  jarfile
                      accepts  a  "jar file" from standard input (for x and t)
                      or sends the "jar file" to standard output  (for  c  and
                      u).

       inputfiles     Files  or  directories,  separated by spaces, to be com-
                      bined into jarfile (for c and u),  or  to  be  extracted
                      (for  x) or listed (for t) from jarfile. All directories
                      are processed  recursively.  The  files  are  compressed
                      unless option O (zero) is used.

       manifest       Pre-existing  manifest  file whose name: value pairs are
                      to be included in MANIFEST.MF in the jar  file.   The  m
                      option  and filename manifest are a pair -- if either is
                      present, they must both appear. The letters m and f must
                      appear  in  the  same  order  that  manifest and jarfile
                      appear.

       -C dir         Temporarily changes directories to dir while  processing
                      the  following  inputfiles  argument.   Multiple  -C dir
                      inputfiles sets are allowed.

       -Joption       Option to be passed into the Java  runtime  environment.
                      (There must be no space between -J and option).

DESCRIPTION
       The  jar  tool  combines multiple files into a single JAR archive file.
       jar is a general-purpose archiving and compression tool, based  on  ZIP
       and  the  ZLIB compression format.  However, jar was designed mainly to
       facilitate the packaging of Java applets or applications into a  single
       archive.   When  the  components  of  an  applet or application (.class
       files, images and sounds) are combined into a single archive, they  can
       be  downloaded by a Java agent (like a browser) in a single HTTP trans-
       action, rather than require a new connection for each piece.  This dra-
       matically  improves download time.  The jar tool also compresses files,
       which further improves download time.  In addition, it allows  individ-
       ual  entries  in a file to be signed by the applet author so that their
       origins can be authenticated.  The syntax for the jar  tool  is  almost
       identical  to  the syntax for the tar(1) command.  A jar archive can be
       used as a class path entry, whether or not it is compressed.

       Typical usage to combine files into a jar file is:

              % jar cf myFile.jar *.class

       In this example, all the class  files  in  the  current  directory  are
       placed  in the file named myjarfile.  A manifest file entry named META-
       INF/MANIFEST.MF is automatically generated  by  the  jar  tool  and  is
       always the first entry in the jar file.  The manifest file is the place
       where any meta-information about the archive is  stored  as  name:value
       pairs.  Refer to the Jar File specification for details about how meta-
       information is stored in the manifest file.

       If you have a pre-existing manifest file whose name:  value  pairs  you
       want  the  jar tool to include for the new jar archive, you can specify
       it using the m option:

            % jar cmf myManifestFile myJarFile *.class

       Be sure that any pre-existing manifest file that you use  ends  with  a
       new  line.  The  last  line of a manifest file will not be parsed if it
       doesn't end with a new line character. Note that when you specify "cfm"
       instead  of  "cmf"  (i.e.,  you  invert  the  order  of the "m" and "f"
       options), you need to specify the name of the jar archive  first,  fol-
       lowed by the name of the manifest file:

            % jar cfm myJarFile myManifestFile *.class

       The manifest is in a text format inspired by RFC822 ASCII format, so it
       is easy to view and process manifest-file contents.

       To extract the files from a jar file, use x , as in:

            % jar xf myFile.jar

       To extract only certain files from a jar file, supply their filenames:

            % jar xf myFile.jar foo bar

       Beginning with version 1.3 of the Java 2 SDK, the jar utility  supports
       JarIndex,  which  allows application class loaders to load classes more
       efficiently from jar files. If an application or applet is bundled into
       multiple  jar  files,   only the necessary jar files will be downloaded
       and opened to load classes. This performance optimization is enabled by
       running jar with the i option. It will generate package location infor-
       mation for the specified main jar file and all the jar files it depends
       on,  which need to be specified in the Class-Path attribute of the main
       jar file's manifest.

            % jar i main.jar

       In this example, an INDEX.LIST  file  is  inserted  into  the  META-INF
       directory  of  main.jar.   The  application  class  loader will use the
       information stored in this file for efficient class loading.  Refer  to
       the  JarIndex  specification for details about how location information
       is stored in the index file.

       A standard way to copy directories is to first compress files  in  dir1
       to standard out, then extract from standard in to dir2 (omitting f from
       both jar commands):

            % (cd dir1; jar c .) | (cd dir2; jar x)

       Examples of using the jar tool to operate on jar  files  and  jar  file
       manifests are provided below and in the Jar trail of the Java Tutorial.

OPTIONS
       c    Creates a new archive file named jarfile (if f is specified) or to
            standard  output  (if  f  and  jarfile are omitted). Add to it the
            files and directories specified by inputfiles.

       u    Updates an existing file jarfile (when f is specified)  by  adding
            to it files and directories specified by inputfiles. For example:

            jar uf foo.jar foo.class

       would  add  the  file foo.class to the existing jar file foo.jar. The u
       option can also update the manifest entry, as given by this example:

            jar umf manifest foo.jar

       updates the foo.jar manifest with the name: value pairs in manifest.

       x    Extracts files and directories from jarfile (if f is specified) or
            standard  input  (if  f and jarfile are omitted). If inputfiles is
            specified,  only  those  specified  files  and   directories   are
            extracted. Otherwise, all files and directories are extracted.

       t    Lists  the  table  of contents from jarfile (if f is specified) or
            standard input (if f and jarfile are omitted).  If  inputfiles  is
            specified,  only those specified files and directories are listed.
            Otherwise, all files and directories are listed.

       i    Generate index information  for  the  specified  jarfile  and  its
            dependent jar files. For example:

            jar i foo.jar

       would  generate  an  INDEX.LIST file in foo.jar which contains location
       information for each package in foo.jar and all the jar files specified
       in the Class-Path attribute of foo.jar.  See the index example.

       f    Specifies  the  file  jarfile  to  be  created  (c),  updated (u),
            extracted (x), indexed (i), or viewed (t). The f option and  file-
            name  jarfile  are  a  pair  -- if present, they must both appear.
            Omitting f and jarfile accepts a "jar file"  from  standard  input
            (for  x  and  t) or sends the "jar file" to standard output (for c
            and u).

       v    Generates verbose output to standard output. Examples shown below.

       0    Zero. Store without using ZIP compression.

       M    Do  not  create  a  manifest file entry (for c and u), or delete a
            manifest file entry if one exists (for u).

       m    Includes name: value attribute pairs from the  specified  manifest
            file  manifest  in the file at META-INF/MANIFEST.MF. A name: value
            pair is added unless one already exists with  the  same  name,  in
            which case its value is updated.

       On  the command line, the letters m and f must appear in the same order
       that manifest and jarfile appear. Example use:

            jar cmf myManifestFile myFile.jar *.class

       You can add special-purpose name: value attribute pairs to the manifest
       that  aren't  contained  in  the  default  manifest.  Examples  of such
       attributes would be those for vendor information, version  information,
       package  sealing,  and to make JAR-bundled applications executable. See
       the JAR Files trail in the Java Tutorial and the Notes  for  Developers
       page for examples of using the m option.

       -C   Temporarily  changes  directories (cd dir) during execution of the
            jar command while processing the  following  inputfiles  argument.
            Its  operation  is  intended to be similar to the -C option of the
            UNIX tar utility.  For example:

               % jar uf foo.jar -C classes bar.classes

       would change to the classes directory and add the bar.class  from  that
       directory to foo.jar. The following command,

               jar uf foo.jar -C classes . -C bin xyz.class

       would  change  to  the  classes  directory and add to foo.jar all files
       within the classes directory (without creating a classes  directory  in
       the jar file), then change back to the original directory before chang-
       ing to the bin directory to add xyz.class to foo.jar. If classes  holds
       files  bar1 and bar2, then here's what the jar file would contain using
       jar tf foo.jar:

               META-INF/
               META-INF/MANIFEST.MF
               bar1
               bar2
               xyz.class

       Joption
            Pass option to the Java runtime environment, where option  is  one
            of  the options described on the man page for the java application
            launcher, java(1).  For example, -J-Xms48m sets the startup memory
            to  48 megabytes. It is a common convention for -J to pass options
            to the underlying virtual machine.

COMMAND LINE ARGUMENT FILES
       To shorten or simplify the jar command line, you  can  specify  one  or
       more files that themselves contain arguments to the jar command (except
       -J options).  This enables you to create jar commands  of  any  length,
       overcoming command line limits imposed by the operating system.

       An  argument  file  can  include  options  and filenames. The arguments
       within a file can be space-separated  or  newline-separated.  Filenames
       within  an argument file are relative to the current directory, not the
       location of the argument file. Wildcards (*) that  might  otherwise  be
       expanded by the operating system shell are not expanded. Use of the '@'
       character to recursively interpret  files  is  not  supported.  The  -J
       options  are  not  supported  because  they are passed to the launcher,
       which does not support argument files.

       When executing jar, pass in the path and name  of  each  argument  file
       with  the '@' leading character. When jar encounters an argument begin-
       ning with the character `@', it expands the contents of that file  into
       the argument list.

       For  example, you could use a single argument file named "classes.list"
       to hold the names of the files:

            % find . -name '*.class' -print > classes.list

       Then execute the jar command passing in the argfile:

            % jar cf my.jar @classes.list

       An argument file can be passed in with a path, but any filenames inside
       the  argument file that have relative paths are relative to the current
       working directory, not the path passed in. Here's such an example:

            % jar @path1/classes.list

EXAMPLES
       To add all the files in a particular directory to an archive (overwrit-
       ing  contents  if  the  archive  already exists). Enumerating verbosely
       (with the "v" option) will tell you more information about the files in
       the archive, such as their size and last modified date.

              % ls
              1.au          Animator.class    monkey.jpg
              2.au          Wave.class        spacemusic.au
              3.au          at_work.gif
              % jar cvf bundle.jar *
              added manifest
              adding: 1.au(in = 2324) (out= 67)(deflated 97%)
              adding: 2.au(in = 6970) (out= 90)(deflated 98%)
              adding: 3.au(in = 11616) (out= 108)(deflated 99%)
              adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
              adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
              adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
              adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
              adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
       If you already have separate subdirectories for images, audio files and
       classes, you can combine them into a single jar file:

              % ls -F
              audio/ classes/ images/

              % jar cvf bundle.jar audio classes images
              added manifest
              adding: audio/(in = 0) (out= 0)(stored 0%)
              adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
              adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
              adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
              adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
              adding: classes/(in = 0) (out= 0)(stored 0%)
              adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
              adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
              adding: images/(in = 0) (out= 0)(stored 0%)
              adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
              adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)

              % ls -F
              audio/ bundle.jar classes/ images/

       To see the entry names in the jarfile, use the t option:

              % jar tf bundle.jar
              META-INF/
              META-INF/MANIFEST.MF
              audio/1.au
              audio/2.au
              audio/3.au
              audio/spacemusic.au
              classes/Animator.class
              classes/Wave.class
              images/monkey.jpg
              images/at_work.gif

       To add an index file to the jar file for speeding up class loading, use
       the "i" option.

       Let's  say  you  split  the  inter-dependent  classes for a stock trade
       application, into three jar files: main.jar, buy.jar, and sell.jar.  If
       you specify the Class-path attribute in the main.jar manifest as:

            Class-Path: buy.jar sell.jar

       then  you  can  use  the  i option to speed up your application's class
       loading time:

            % jar i main.jar

       An INDEX.LIST file is inserted to the  META-INF  directory  which  will
       enable the application class loader to download the specified jar files
       when it is searching for classes or resources.

SEE ALSO
       The JAR Overview @
         http://java.sun.com/javase/6/docs/technotes/guides/jar/jarGuide.html


       The JAR File Specification @
         http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html


       The JARIndex Spec @
         http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html


       JAR Tutorial @
         http://java.sun.com/docs/books/tutorial/jar/


       pack200 Reference Page @
         http://java.sun.com/javase/6/docs/technotes/tools/share/pack200.html




                                  22 Jun 2004
==============================================[jar man  end 2017-12-01 10:05]===============================================

 

 

分享到:
评论

相关推荐

    解压用到的jar包

    在Java编程环境中,有时我们需要对文件进行压缩或解压缩操作,这通常涉及到使用特定的库或框架。在给定的“解压用到的jar包”中,包含了两个关键的库:ant-1.6.5.jar和junrar-0.7.jar。这两个库为Java开发者提供了...

    压缩解压所需jar包支持各种压缩格式

    - `Compressor` 和 `Decompressor`:压缩和解压缩的抽象接口,提供了压缩和解压缩的通用方法。 3. **使用示例**: - 压缩文件到ZIP: ```java File file = new File("path/to/file"); FileOutputStream fos = ...

    利用ant.jar解压缩zip包

    此外,如果你需要在命令行环境中使用ant.jar,可以编写一个简单的Ant构建文件(build.xml),并使用`unzip`任务来解压缩ZIP文件。例如: ```xml ``` 然后通过命令行运行`ant unzip`即可。 总的来说,利用...

    解压tar.Z文件,含jar包

    总之,处理tar.Z文件需要两步操作,理解`tar`和`compress`的用法,以及如何处理解压后的jar包,对于IT专业人士来说是非常基础且重要的技能。在工作中遇到这样的文件时,不要惊慌,按照上述步骤操作即可。

    java解压缩zip代码与用到的jar包

    在本篇中,我们将深入探讨如何使用Java API来实现ZIP文件的解压缩,以及可能需要用到的第三方库。 首先,Java标准库(Java Standard Library)自身提供了对ZIP文件的支持。在`java.util.zip`包中,有两个关键类用于...

    java解压7z用到的jar及解压方法

    接下来,我们将讨论如何编写解压7z文件的方法。以下是一个简单的示例代码片段: ```java import com.igormaznitsa.sciareto.utils.IOUtils; import net.sf.sevenzipjbinding.ISevenZipInArchive; import ...

    Java zip,rar 压缩解压,含jar包

    本篇文章将详细讲解如何使用Java对zip和rar格式进行压缩与解压操作,同时也会涉及jar包的处理。 首先,Java标准库提供了一个名为`java.util.zip`的包,该包包含了用于处理zip文件的类,如`ZipOutputStream`和`...

    java zipentry.jar 解决解压失败问题

    2. **遍历和解压ZIP条目**:使用`getNextEntry()`方法逐个处理ZIP条目,确保在解压每个条目后调用`closeEntry()`。 ```java ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { String entryName = ...

    zip压缩java工具类包含jar文件

    在Java编程环境中,压缩和解压文件是常见的需求,尤其是对于大数据处理和文件传输。`zip`格式是一种广泛使用的文件压缩格式,具有高效且兼容性强的特点。本篇将详细讲解如何利用Java工具类进行`zip`压缩和解压操作,...

    java解压和压缩tar包

    本文将详细讲解如何使用Java来解压和压缩tar包,同时解决在处理中文文件名时可能出现的乱码问题,主要关注`javatar-2.5.jar`库中的功能以及`TarUtil.java`类的应用。 首先,`javatar-2.5.jar`是一个专门用于处理tar...

    unix下常用解压和压缩命令.txt

    #### 描述:本文档介绍了 Unix 系统中常用的解压与压缩命令,包括但不限于 tar、gzip、bzip2 等工具的使用方法。 在 Unix 系统中,文件的打包和压缩是非常常见的操作。尽管“tar”命令常被误认为是压缩工具,但实际...

    java解压zip或rar压缩文件源码与jar包

    综上所述,这个Java接口类解决了在解压ZIP和RAR文件时可能出现的乱码问题,通过自定义的解压方法,提供了稳定且兼容的解压缩功能。开发者可以方便地在自己的项目中集成这个接口,以便处理各种压缩文件。

    java解压jar包及示例

    本文将深入探讨如何使用Java实现RAR压缩和解压,以及如何利用提供的jar包(java-unrar-0.3.jar和ant.jar)进行操作,并结合`DeCompressUtil.java`提供的示例代码来理解其实现。 首先,`java-unrar-0.3.jar`是一个...

    pepk.jar Pepk签名压缩工具

    在本文中,我们将深入探讨PEPK.jar的工作原理、功能、使用方法以及它在AppGallery Connect中的角色。 1. **PEPK.jar的工作原理**: PEPK.jar工具使用了先进的压缩算法,能够有效地减小APK的体积,尤其是对于包含...

    rar文件压缩解压(java)

    本篇文章将详细介绍如何使用Java来实现RAR文件的压缩和解压操作。 首先,Java标准库并没有直接支持RAR文件的操作,所以我们需要借助第三方库,如Apache Commons Compress或jRar。Apache Commons Compress库提供了对...

    JAVA解压ZIP多层目录文件(需ant.jar

    ### JAVA解压ZIP多层目录文件(需ant.jar) #### 概述 本文将详细介绍一个Java方法,该方法用于解压包含多层目录结构的ZIP文件,并能够支持中文文件名。这种方法利用了Apache Ant库中的`org.apache.tools.zip....

    解压cab文件Jar包mscab.jar

    总的来说,理解和操作CAB文件需要对文件压缩格式有一定的理解,同时,使用`mscab.jar`这样的Java库则要求掌握Java编程和库的使用技巧。在实际开发中,确保选择适合项目需求的库,并进行充分的测试以保证其稳定性和...

    spring4.3.14.RELEASE版jar包【整合包,包含所有的主要jar包】-正式版下载

    #### 四、安装与使用方法 1. **下载整合包**:从官方提供的链接下载 `spring-framework-4.3.14.RELEASE-dist.zip`。 2. **解压文件**:将下载好的文件解压缩到指定目录下。 3. **添加 JAR 包**:将需要的 JAR 包...

    java 解压jar

    Java 语言提供了多种解压缩 RAR 文件的方法,其中之一是使用 unrar.jar 库。 unrar.jar 库是一个 Java 库,它可以用于解压缩 RAR 文件。使用这个库可以避免使用命令行调用 WinRAR.exe,这可以避免出现解压缩页面和...

Global site tag (gtag.js) - Google Analytics