I have two classes. I created a JAR file using:
jar cvf practice.jar class1.class class2.class
Then I set the starting entry point:
jar cfe practice.jar class1 class1.class
When I execute the JAR file, it works fine until the point where there is a transition to the next class, i.e. class2 hey = new class2(); Then it exits out. But want to continue to the next class.
It should go to class2.class. Since it is saying in that object. Apparently, it does not.
public class class1 {
public static void main(String[] args){
JOptionPane.showMessageDialog(null, "This is class 1", "Order",JOptionPane.PLAIN_MESSAGE);
class2 hey = new class2();
}
}
public class class2 {
public class2() {
JOptionPane.showMessageDialog(null, "This is class 2", "Order",JOptionPane.PLAIN_MESSAGE);
}
}
I tried your example and I get a NoClassDefFound for
class2after pressing “OK” in the first window. That is because theclass2.classis not present in thepractice.jarfile.Try the following instead of both your
jar ...commands: