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 ?
-
Not clear. Can you please Explain with some code snippet?Subhrajyoti Majumder– Subhrajyoti Majumder2012年10月09日 07:13:17 +00:00Commented Oct 9, 2012 at 7:13
-
I have a program with 2 files. file1 and file2-has java main and calls file1. I was able to print data and all. but when I did jar file I am not able to print anything. infact there is no print line I have exactly after main ..so looks my main immedite line is not executedThe Learner– The Learner2012年10月09日 07:14:22 +00:00Commented Oct 9, 2012 at 7:14
-
1How are you executing your .jar ?User404– User4042012年10月09日 07:17:36 +00:00Commented Oct 9, 2012 at 7:17
-
what does your manifest look like?mcalex– mcalex2012年10月09日 07:25:52 +00:00Commented Oct 9, 2012 at 7:25
-
I do not have manifest file. i am using Extract required binaries option. I had some warnings it says export with compile warning in details...not sure how to see the warningsThe Learner– The Learner2012年10月09日 07:31:20 +00:00Commented Oct 9, 2012 at 7:31
2 Answers 2
The problem you are mentioning is because, the compiler can not find the main class within the jar. To solve this we use a MANIFEST file.
A MANIFEST file is a special file that contains information about the files packaged in JAR
refer here for details on MANIFESTS
To solve your problem. we need to define a MANIFEST file and define the main Class inside it.
Create a MANIFEST.MF
file for your jar and specify the class that has the main method using format
Main-Class: Mypackage.yourPackhage.OurClass
UPDATE
when you are creating the JAR, follow Define Jar Manifest
to Include a Manifest file in your jar
UPDATE 2
Structure should be like
YourJAR
META-INF\MANIFEST.MF
CLASS1
CLASS2
4 Comments
A manifest is a one-line text file with a "Main-Class" directive. You need to create this file (call it something useful like manifest.txt) in notepad or wherever.
In the file you want the line: Main-Class: file2
make sure there's a hard return at the end of the line.
Then use jar like this:
jar cvfm sample.jar manifest.txt *.class