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

时间:2015-07-20 19:19:35

标签: java executable-jar

我有一组文件(java,class,html),我将这些文件放入名为calc.jar的.jar文件中:

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

它创建一个"可执行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文件包含main方法。

2 个答案:

答案 0 :(得分:0)

输出清楚地说

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

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

基本上你是以错误的方式使用jar命令。请仔细阅读手册页或使用方法,然后重试。

答案 1 :(得分:0)

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

尝试这样的事情:

java -jar calc.jar calc

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