Reputation: 33
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.
Ex.
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");
}
}
Now i create a jar file containing these 2 classes A and 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();
}
}
How do i compile and run Main class?
Thanks
Upvotes: 0
Views: 49
Reputation: 5868
Try following: javac -classpath Main.java
here -classpath is the path of your jar file.
Upvotes: 0
Reputation: 68905
You can do
java -classpath yourJarFile.jar other.Main
You can also specify it in manifest file in jar (documentation).
Upvotes: 1