当我使用.jar 文件存储一组程序组件时,它不会运行

When I use a .jar file to store a set of program components, it won't run

我将一组文档(java、class、html)放入名为 calc.jar 的 .jar 文件中,其中:

jar cmf MANIFEST.MF calc.jar calc.java calc.class calc.html

它在我的文件夹中创建了一个 "executable jar" 文件,但当我打开它时它什么也没做。然后我 运行 cmd 中的文件具有以下内容:

jar -jar calc.jar

之后是:

Illegal option: j
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] f
iles ...
Options:
-c  create new archive
-t  list table of contents for archive
-x  extract named (or all) files from archive
-u  update existing archive
-v  generate verbose output on standard output
-f  specify archive file name
-m  include manifest information from specified manifest file
-n  perform Pack200 normalization after creating a new archive
-e  specify application entry point for stand-alone application
    bundled into an executable jar file
-0  store only; use no ZIP compression
-P  preserve leading '/' (absolute path) and ".." (parent directory) compone
nts from file names
-M  do not create a manifest file for the entries
-i  generate index information for the specified jar files
-C  change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar:
   jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
       files in the foo/ directory into 'classes.jar':
   jar cvfm classes.jar mymanifest -C foo/ .

这是怎么回事?!?

编辑:我的清单文件显示为:

Manifest-version: 1.0
Main-Class: calc

使用 java -jar calc.jar 显示:

Error: Main method not found in class calc, please define the main method

但是,我的 .java 文件包含主要方法。

输出清楚地说

-j
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] f
iles ...

-j 不支持,正如 NESPowerGlove 正确指出的那样。

基本上你在错误地使用 jar 命令。请仔细阅读手册页或用法,然后重试。

命令行语法已关闭。您正在尝试使用 jar 命令执行 .jar 文件,该命令仅用于打包文件。

尝试这样的事情:

java -jar calc.jar 计算

带-jar分隔符的java命令表示您要执行一个jar文件。