1

I am using Eclipse for running my applications.

=> All this time I have been running as a java application (using Run as Java application option) and it works.My program executes for 20 minutes and prints some data .

Now I tried to create a Runnable jar. I am able to get jar file and execute.But it exits after 1 minutes.There are no prints from SOP.I have kept one just immediately after main and that is also not getting printed. How to debug this?

I am getting this Error now:

JAR export finished with warnings. See details for additional information.
  Exported with compile warnings:input.java
  Jar export finished with problems. See details for additional information.
    Could not find main method from given launch configuration.

But there is a public static void main(String[] args) in the input.java file. I am not sure why is it complaining when I try to run from command prompt and it gives no main manifest attribute.I did not create any file with that name. What has gone wrong here ?

4

2 回答 2

2

您提到的问题是因为编译器在 jar 中找不到主类。为了解决这个问题,我们使用 MANIFEST 文件。

MANIFEST 文件是一个特殊文件,其中包含有关打包在 JAR 中的文件的信息

有关清单的详细信息,请参阅此处

来解决你的问题。我们需要定义一个 MANIFEST 文件并在其中定义主类。

创建一个MANIFEST.MF

jar 文件并使用格式指定具有主要方法的类

Main-Class: Mypackage.yourPackhage.OurClass

更新

创建 JAR 时,请遵循Define Jar Manifest

在你的 jar 中包含一个 Manifest 文件

更新 2

结构应该像

YourJAR
    META-INF\MANIFEST.MF
    CLASS1
    CLASS2
于 2012-10-09T07:51:34.940 回答
0

清单是带有“Main-Class”指令的单行文本文件。您需要在记事本或任何地方创建此文件(称其为有用的东西,例如 manifest.txt)。

在你想要的文件中: Main-Class: file2

确保在行尾有一个硬回报。

然后像这样使用jar: jar cvfm sample.jar manifest.txt *.class

于 2012-10-09T09:36:42.740 回答