编译并执行引用jar中类文件的主类 [英] Compiling and executing main class which refers to class files in jar
本文介绍了编译并执行引用jar中类文件的主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Java的新手,想知道如何编译和执行引用jar中类文件的主类.
I am a newbie to java and would like to know how to compile and execute main class which refers to class files in jar.
例如.
package com.java;
public class A {
public void a(){
System.out.println("In A");
}
}
package com.java;
public class B extends A {
public void b(){
System.out.println("In B");
}
}
现在,我创建一个包含这两个类A和B的jar文件.
Now i create a jar file containing these 2 classes A and B.
我有一个主类,它引用了A类和B类.
I have a main class which refers classes A and B.
package other;
public class Main {
public static void main(String[] args){
A a = new A();
B b = new B();
a.a();
b.b();
}
}
我如何编译和运行Main class?
How do i compile and run Main class?
谢谢
推荐答案
您可以
java -classpath yourJarFile.jar other.Main
您还可以在jar的清单文件中指定它(文档).
You can also specify it in manifest file in jar (documentation).
这篇关于编译并执行引用jar中类文件的主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文