我正在尝试创建一个 jar 并为包结构化 java 程序执行它。我能够创建 jar,但我正在执行它的抛出错误。
文件夹结构:Java_Example > pack > A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
文件夹结构:Java_Example > mypack > B.java
package mypack;
import pack.*;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
文件夹结构:Java_Example > bin > Manifest.txt
Mainfest-Version: 1.1
Main-Class: mypack.B
清单文件与换行符一起存在
从命令行执行
E:\Java_Example\bin>java -cp E:\Java_Example mypack.B
Hello
创建罐子
E:\Java_Example\bin>jar cvf MyJar.jar Manifest.txt E:\Java_Example\pack\A.clas
E:\Java_Example\mypack\B.class
added manifest
adding: Manifest.txt(in = 60) (out= 61)(deflated -1%)
adding: Java_Example/pack/A.class(in = 376) (out= 268)(deflated 28%)
adding: Java_Example/mypack/B.class(in = 307) (out= 237)(deflated 22%)
执行罐
E:\Java_Example\bin>jar -jar MyJar.jar
Illegal option: j
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] f
iles ...
java -jar 命令执行
E:\Java_Example\bin>java -jar MyJar.jar
no main manifest attribute, in MyJar.jar
尝试通过给主类执行 Jar
E:\Java_Example\bin>jar -cp MyJar.jar mypack.B
Illegal option: p
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] f
iles ...
jar -tf 输出
E:\Java_Example\bin>jar -tf MyJar.jar
META-INF/
META-INF/MANIFEST.MF
Manifest.txt
Java_Example/pack/A.class
Java_Example/mypack/B.class
慕姐4208626
倚天杖
相关分类