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 ?

sakthisundar
3,2863 gold badges18 silver badges30 bronze badges
asked Oct 9, 2012 at 7:10
5
  • Not clear. Can you please Explain with some code snippet? Commented 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 executed Commented Oct 9, 2012 at 7:14
  • 1
    How are you executing your .jar ? Commented Oct 9, 2012 at 7:17
  • what does your manifest look like? Commented 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 warnings Commented Oct 9, 2012 at 7:31

2 Answers 2

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
answered Oct 9, 2012 at 7:51
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Mukul. what if I dont have ant package name? I have 2 files, 1 class is having main and another classs is used by main class. so how sould I have the contents. just main class is fine? and also the file structure where I should create?
I am seeing this Error: JAR export finished with warnings. See details for additional information. Exported with compile warnings: sample.java Jar export finished with problems. See details for additional information. Could not find main method from given launch configuration.
if you dont have any package name, then just put the class name. you should create MAINFIEST.MF file inside a META-INF folder refer to update 2 for sample structure
@TheLearner by the way, can you update the post with command for how did you create your jar and how are you running it?
0

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

answered Oct 9, 2012 at 9:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.