I have the following code in main class it works if i run the program through netbeans. But when i open the jar made by netbeans it seems as if i had not written anything in main except the new FormTTS().setVisible(true);
If i write
如果我通过netbeans运行程序,我在主类中有以下代码。但是当我打开netbeans制作的jar时,好像我没有在main中写任何东西,除了新的FormTTS()。setVisible(true);如果我写
public static void main(String args[])throws Exception {
System.exit(0);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(null,"1125");
new FormTTS().setVisible(true);
}
});
}
It is so strange that the program just exits by running from netbeans BUT not so in JAR, if jar is runned, it opens FormTTS!!!
很奇怪,程序只是从netbeans运行而不是在JAR中运行,如果运行jar,它会打开FormTTS!
I can't do without this, as i have some other code that has to be replaced by exit() and that needs throw exception(which i cant do from any other function or button than main())
我不能没有这个,因为我有一些其他代码必须由exit()替换,并且需要抛出异常(我不能从除main()之外的任何其他函数或按钮)
I ensured that the jar is updated BY: I changes something in the FormTTS after placing exit in main; and i can see that change from the JAR.
我确保jar更新BY:在main中退出后我在FormTTS中更改了一些内容;我可以看到JAR的变化。
Editied What i did now is; i removed all the code in main and it doesnt work in netbeans(obvious) BUT FormTTS OPENS IN JAR!!!! Ensured that the JAR is of that program by deleting the JAR, clean building the project and opening the JAR
编辑我现在做的是;我删除了main中的所有代码,它在netbeans中不起作用(显而易见)但是FormTTS在JAR中打开!!!!通过删除JAR,清理构建项目并打开JAR,确保JAR属于该程序
1 个解决方案
#1
0
Double-check your JAR. If you run javap -classpath test.jar -c package.ClassName
you'll see the bytecode and it should look something like this if indeed your System.exit statement is being included in the jar file:
仔细检查你的JAR。如果您运行javap -classpath test.jar -c package.ClassName,您将看到字节码,如果您的System.exit语句确实包含在jar文件中,它应该看起来像这样:
C:\Users\UFL1138\Desktop>javap -classpath test.jar -c test.TestByteCode
Compiled from "TestByteCode.java"
public class test.TestByteCode extends java.lang.Object{
public test.TestByteCode();
Code:
0: aload_0
1: invokespecial #8; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.Exception;
Code:
0: iconst_0
<IMPORTANT_PART>
1: invokestatic #19; //Method java/lang/System.exit:(I)V
</IMPORTANT_PART>
4: new #25; //class test/TestByteCode$1
7: dup
8: invokespecial #27; //Method test/TestByteCode$1."<init>":()V
11: invokestatic #28; //Method java/awt/EventQueue.invokeLater:(Ljava/lang/Runnable;)V
14: return
}
#1
0
Double-check your JAR. If you run javap -classpath test.jar -c package.ClassName
you'll see the bytecode and it should look something like this if indeed your System.exit statement is being included in the jar file:
仔细检查你的JAR。如果您运行javap -classpath test.jar -c package.ClassName,您将看到字节码,如果您的System.exit语句确实包含在jar文件中,它应该看起来像这样:
C:\Users\UFL1138\Desktop>javap -classpath test.jar -c test.TestByteCode
Compiled from "TestByteCode.java"
public class test.TestByteCode extends java.lang.Object{
public test.TestByteCode();
Code:
0: aload_0
1: invokespecial #8; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.Exception;
Code:
0: iconst_0
<IMPORTANT_PART>
1: invokestatic #19; //Method java/lang/System.exit:(I)V
</IMPORTANT_PART>
4: new #25; //class test/TestByteCode$1
7: dup
8: invokespecial #27; //Method test/TestByteCode$1."<init>":()V
11: invokestatic #28; //Method java/awt/EventQueue.invokeLater:(Ljava/lang/Runnable;)V
14: return
}