{
    "mode": "man",
    "parameter": "jar",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/jar/1/json",
    "generated": "2026-10-21T11:33:17Z",
    "synopsis": "Create JAR file\njar c[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]\nUpdate JAR file\njar u[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]\nExtract JAR file\njar x[vf] [jarfile] file ... [-Joption ...] [@arg-file ...]\nList Contents of JAR file\njar t[vf] [jarfile] file ... [-Joption ...] [@arg-file ...]\nAdd Index to JAR file\njar i jarfile [-Joption ...] [@arg-file ...]",
    "sections": {
        "NAME": {
            "content": "jar - Manipulates Java Archive (JAR) files.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Create JAR file\n\n\njar c[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]\n\n\nUpdate JAR file\n\n\njar u[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]\n\n\nExtract JAR file\n\n\njar x[vf] [jarfile] file ... [-Joption ...] [@arg-file ...]\n\n\nList Contents of JAR file\n\n\njar t[vf] [jarfile] file ... [-Joption ...] [@arg-file ...]\n\n\nAdd Index to JAR file\n\n\njar i jarfile [-Joption ...] [@arg-file ...]\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The jar command is a general-purpose archiving and compression tool, based on ZIP and the\nZLIB compression format. However, the jar command was designed mainly to package Java applets\nor applications into a single archive. When the components of an applet or application\n(files, images and sounds) are combined into a single archive, they can be downloaded by a\nJava agent (such as a browser) in a single HTTP transaction, rather than requiring a new\nconnection for each piece. This dramatically improves download times. The jar command also\ncompresses files, which further improves download time. The jar command also allows\nindividual entries in a file to be signed by the applet author so that their origin can be\nauthenticated. A JAR file can be used as a class path entry, whether or not it is compressed.\n\nThe syntax for the jar command resembles the syntax for the tar command. It has several\noperation modes, defined by one of the mandatory operation arguments. Other arguments are\neither options that modify the behavior of the operation, or operands required to perform the\noperation.\n",
            "subsections": []
        },
        "OPERATION ARGUMENTS": {
            "content": "When using the jar command, you have to select an operation to be performed by specifying one\nof the following operation arguments. You can mix them up with other one-letter options on\nthe command line, but usually the operation argument is the first argument specified.\n\nc      Create a new JAR archive.\n\ni      Generate index information for a JAR archive.\n\nt      List the contents of a JAR archive.\n\nu      Update a JAR archive.\n\nx      Extract files from a JAR archive.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "Use  the  following  options to customize how the JAR file is created, updated, extracted, or\nviewed:\n\ne      Sets the class specified by the entrypoint  operand  to  be  the  entry  point  for  a\nstandalone  Java  application  bundled  into  an  executable JAR file. The use of this\noption creates or overrides the Main-Class attribute value in the manifest file. The e\noption can be used when creating (c) or updating (u) the JAR file.\n\nFor example, the following command creates the Main.jar archive  with  the  Main.class\nfile where the Main-Class attribute value in the manifest is set to Main:\n\njar cfe Main.jar Main Main.class\n\n\n\nThe  Java  Runtime Environment (JRE) can directly call this application by running the\nfollowing command:\n\njava -jar Main.jar\n\n\n\nIf the entry point class name is in a package, then it could use either the dot (.) or\nslash (/) as the delimiter. For example, if Main.class is in a package  called  mydir,\nthen the entry point can be specified in one of the following ways:\n\njar -cfe Main.jar mydir/Main mydir/Main.class\njar -cfe Main.jar mydir.Main mydir/Main.class\n\n\n\nNote\n\nSpecifying  both m and e options together when a particular manifest also contains the\nMain-Class attribute results in an ambiguous Main-Class specification.  The  ambiguity\nleads to an error and the jar command creation or update operation is terminated.\n\nf      Sets  the file specified by the jarfile operand to be the name of the JAR file that is\ncreated (c), updated (u), extracted (x) from, or viewed (t). Omitting the f option and\nthe jarfile operand instructs the jar command to accept the JAR file name  from  stdin\n(for x and t) or send the JAR file to stdout (for c and u).\n\nm      Includes  names  and  values  of  attributes  from  the file specified by the manifest\noperand in the manifest file of the jar command  (located  in  the  archive  at  META-\nINF/MANIFEST.MF).  The jar command adds the attribute’s name and value to the JAR file\nunless an entry already exists with the same name,  in  which  case  the  jar  command\nupdates  the  value  of  the  attribute. The m option can be used when creating (c) or\nupdating (u) the JAR file.\n\nYou can add special-purpose name-value attribute pairs to the manifest  that  are  not\ncontained  in  the  default  manifest  file.  For example, you can add attributes that\nspecify vendor information, release information, package  sealing,  or  to  make  JAR-\nbundled  applications  executable.  For  examples of using the m option, see Packaging\nPrograms at http://docs.oracle.com/javase/tutorial/deployment/jar/index.html\n\nM      Does not create a manifest file entry (for c and u), or delete a manifest  file  entry\nwhen  one  exists  (for u). The M option can be used when creating (c) or updating (u)\nthe JAR file.\n\nn      When creating (c) a JAR file, this option normalizes the archive so that  the  content\nis  not  affected  by  the packing and unpacking operations of the pack200(1) command.\nWithout this normalization, the signature of a signed JAR can become invalid.\n\nv      Generates verbose output to standard output. See Examples.\n\n0      (Zero) Creates (c) or updates (u) the JAR file without using ZIP compression.\n\n-C dir\nWhen creating (c) or updating (u) a JAR file,  this  option  temporarily  changes  the\ndirectory  while  processing  files  specified  by the file operands. Its operation is\nintended to be similar to the -C option of  the  UNIX  tar  utility.For  example,  the\nfollowing  command  changes  to the classes directory and adds the Bar.class file from\nthat directory to my.jar:\n\njar uf my.jar -C classes Bar.class\n\n\n\nThe following command changes to the classes directory and adds to  my.jar  all  files\nwithin  the  classes directory (without creating a classes directory in the JAR file),\nthen changes back to the original directory before changing to the  bin  directory  to\nadd Xyz.class to my.jar.\n\njar uf my.jar -C classes . -C bin Xyz.class\n\n\n\nIf classes contained files bar1 and bar2, then the JAR file will contain the following\nafter running the previous command:\n\n% jar tf my.jar\nMETA-INF/\nMETA-INF/MANIFEST.MF\nbar1\nbar2\nXyz.class\n\n\n",
            "subsections": [
                {
                    "name": "-J_option_",
                    "content": "Sets  the  specified JVM option to be used when the JRE runs the JAR file. JVM options\nare described on the reference page for the java(1) command.  For  example,  -J-Xms48m\nsets the startup memory to 48 MB.\n"
                }
            ]
        },
        "OPERANDS": {
            "content": "The following operands are recognized by the jar command.\n\nfile   When  creating  (c)  or updating (u) a JAR file, the file operand defines the path and\nname of the file or directory that should be added to the archive. When extracting (x)\nor listing the contents (t) of a JAR file, the file operand defines the path and  name\nof  the  file  to  be extrated or listed. At least one valid file or directory must be\nspecified. Separate multiple file operands with spaces. If the entrypoint, jarfile, or\nmanifest operands are used, the file operands must be specified after them.\n\nentrypoint\nWhen creating (c) or updating (u) a JAR file, the entrypoint operand defines the  name\nof  the class that should be the entry point for a standalone Java application bundled\ninto an executable JAR file. The entrypoint operand must be specified if the e  option\nis present.\n\njarfile\nDefines  the name of the file to be created (c), updated (u), extracted (x), or viewed\n(t). The jarfile operand must be specified if the f option is present. Omitting the  f\noption  and  the jarfile operand instructs the jar command to accept the JAR file name\nfrom stdin (for x and t) or send the JAR file to stdout (for c and u).\n\nWhen indexing (i) a JAR file, specify the jarfile operand without the f option.\n\nmanifest\nWhen creating (c) or updating (u)  a  JAR  file,  the  manifest  operand  defines  the\npreexisting  manifest  files  with  names  and  values of attributes to be included in\nMANIFEST.MF in the JAR file. The manifest operand must be specified if the f option is\npresent.\n\n@arg-file\nTo shorten or simplify the jar command, you can specify arguments in a  separate  text\nfile  and  pass  it  to the jar command with the at sign (@) as a prefix. When the jar\ncommand encounters an argument beginning with the at sign, it expands the contents  of\nthat file into the argument list.\n\nAn  argument  file can include options and arguments of the jar command (except the -J\noptions, because they are passed to the launcher,  which  does  not  support  argument\nfiles).  The arguments within a file can be separated by spaces or newline characters.\nFile names within an argument file are relative to the current  directory  from  which\nyou  run  the  jar  command,  not  relative to the location of the argument file. Wild\ncards, such as the asterisk (*), that might otherwise be  expanded  by  the  operating\nsystem shell, are not expanded.\n\nThe  following  example,  shows  how to create a classes.list file with names of files\nfrom the current directory output by the find command:\n\nfind . -name '*.class' -print > classes.list\n\n\n\nYou can then execute the jar command and pass the classes.list file to  it  using  the\n@arg-file syntax:\n\njar cf my.jar @classes.list\n\n\n\nAn  argument file can be specified with a path, but any file names inside the argument\nfile that have relative paths are relative to the current working directory of the jar\ncommand, not to the path passed in, for example:\n\njar @dir/classes.list\n\n\n",
            "subsections": []
        },
        "NOTES": {
            "content": "The e, f, and m options must appear in the same order on the command line as the  entrypoint,\njarfile, and manifest operands, for example:\n\njar cmef myManifestFile MyMainClass myFile.jar *.class\n\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "",
            "subsections": [
                {
                    "name": "Example 1 Adding All Files From the Current Directory With Verbose Output",
                    "content": ""
                },
                {
                    "name": "% ls",
                    "content": ""
                },
                {
                    "name": "1.au          Animator.class    monkey.jpg",
                    "content": ""
                },
                {
                    "name": "2.au          Wave.class        spacemusic.au",
                    "content": ""
                },
                {
                    "name": "3.au          at_work.gif",
                    "content": "% jar cvf bundle.jar *"
                },
                {
                    "name": "added manifest",
                    "content": ""
                },
                {
                    "name": "adding: 1.au(in = 2324) (out= 67)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "adding: 2.au(in = 6970) (out= 90)(deflated 98%)",
                    "content": ""
                },
                {
                    "name": "adding: 3.au(in = 11616) (out= 108)(deflated 99%)",
                    "content": ""
                },
                {
                    "name": "adding: Animator.class(in = 2266) (out= 66)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "adding: Wave.class(in = 3778) (out= 81)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)",
                    "content": ""
                },
                {
                    "name": "adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)",
                    "content": ""
                },
                {
                    "name": "adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "Example 2 Adding Files From Subdirectories",
                    "content": ""
                },
                {
                    "name": "% ls -F",
                    "content": ""
                },
                {
                    "name": "audio/ classes/ images/",
                    "content": ""
                },
                {
                    "name": "% jar cvf bundle.jar audio classes images",
                    "content": ""
                },
                {
                    "name": "added manifest",
                    "content": ""
                },
                {
                    "name": "adding: audio/(in = 0) (out= 0)(stored 0%)",
                    "content": ""
                },
                {
                    "name": "adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)",
                    "content": ""
                },
                {
                    "name": "adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)",
                    "content": ""
                },
                {
                    "name": "adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "adding: classes/(in = 0) (out= 0)(stored 0%)",
                    "content": ""
                },
                {
                    "name": "adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)",
                    "content": ""
                },
                {
                    "name": "adding: images/(in = 0) (out= 0)(stored 0%)",
                    "content": ""
                },
                {
                    "name": "adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)",
                    "content": ""
                },
                {
                    "name": "adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)",
                    "content": ""
                },
                {
                    "name": "% ls -F",
                    "content": ""
                },
                {
                    "name": "audio/ bundle.jar classes/ images/",
                    "content": ""
                },
                {
                    "name": "Example 3 Listing the Contents of JAR",
                    "content": ""
                },
                {
                    "name": "% jar tf bundle.jar",
                    "content": "META-INF/"
                },
                {
                    "name": "META-INF/MANIFEST.MF",
                    "content": ""
                },
                {
                    "name": "audio/1.au",
                    "content": ""
                },
                {
                    "name": "audio/2.au",
                    "content": ""
                },
                {
                    "name": "audio/3.au",
                    "content": ""
                },
                {
                    "name": "audio/spacemusic.au",
                    "content": ""
                },
                {
                    "name": "classes/Animator.class",
                    "content": ""
                },
                {
                    "name": "classes/Wave.class",
                    "content": ""
                },
                {
                    "name": "images/monkey.jpg",
                    "content": ""
                },
                {
                    "name": "images/at_work.gif",
                    "content": ""
                },
                {
                    "name": "Example 4 Adding an Index",
                    "content": "Use the i option when you split the interdependent classes for a stock trade application into\nthree  JAR files: main.jar, buy.jar, and sell.jar. If you specify the Class-Path attribute in\nthe main.jar manifest, then you can use the i option to speed up the class loading  time  for\nyour application:\n"
                },
                {
                    "name": "Class-Path: buy.jar sell.jar",
                    "content": ""
                },
                {
                    "name": "jar i main.jar",
                    "content": "An  INDEX.LIST file is inserted to the META-INF directory. This enables the application class\nloader to download the specified JAR files when it is searching for classes or resources.\n\nThe application class loader uses the information stored in this  file  for  efficient  class\nloading.  To  copy  directories,  first  compress  files in dir1 to stdout, then pipeline and\nextract from stdin to dir2 (omitting the -f option from both jar commands):\n"
                },
                {
                    "name": "(cd dir1; jar c .) | (cd dir2; jar x)",
                    "content": ""
                }
            ]
        },
        "SEE ALSO": {
            "content": "• pack200(1).\n\n• The        JAR        section        of        The        Java         Tutorials         at\nhttp://docs.oracle.com/javase/tutorial/deployment/jar/index.html\n\nJDK 8                                     21 November 2013                                    jar(1)",
            "subsections": []
        }
    },
    "summary": "jar - Manipulates Java Archive (JAR) files.",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Sets the specified JVM option to be used when the JRE runs the JAR file. JVM options are described on the reference page for the java(1) command. For example, -J-Xms48m sets the startup memory to 48 MB."
        }
    ],
    "examples": [
        "% jar cvf bundle.jar *",
        "META-INF/",
        "Use the i option when you split the interdependent 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, then you can use the i option to speed up the class loading  time  for",
        "your application:",
        "An  INDEX.LIST file is inserted to the META-INF directory. This enables the application class",
        "loader to download the specified JAR files when it is searching for classes or resources.",
        "The application class loader uses the information stored in this  file  for  efficient  class",
        "loading.  To  copy  directories,  first  compress  files in dir1 to stdout, then pipeline and",
        "extract from stdin to dir2 (omitting the -f option from both jar commands):"
    ],
    "see_also": [
        {
            "name": "pack200",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pack200/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Java applications/libraries packager.",
        "examples": [
            {
                "description": "Recursively archive all files in the current directory into a `.jar` file",
                "command": "jar cf {{file.jar}} *"
            },
            {
                "description": "Unzip `.jar`/`.war` file to the current directory",
                "command": "jar -xvf {{file.jar}}"
            },
            {
                "description": "List a `.jar`/`.war` file content",
                "command": "jar tf {{path/to/file.jar}}"
            },
            {
                "description": "List a `.jar`/`.war` file content with verbose output",
                "command": "jar tvf {{path/to/file.jar}}"
            }
        ]
    }
}