Link to home
Start Free TrialLog in
Avatar of dshrenik
dshrenikFlag for United States of America

asked on

Build executable jar

Please let me know how I can build an executable .jar out of my project.

Thanks!
Avatar of for_yan
for_yan
Flag of United States of America image

Are you using some IDE ?
Avatar of dshrenik

ASKER

I am using Eclipse.
You'll find in that link above even two ways - one is in the question itself - another is inthe answer
I get this error when I try to run thecreated .jar:
Failed to load Main-Class manifest attribute
and this is even youtibe tutoarila
http://www.youtube.com/watch?v=Czmc2-hSBuk
wellcopy this .jar to .zip - unzip it and check if you have manifest.mf file and if it syas waht is your main class
If not, try to recreate it jar again
It has just this info:

Manifest-Version: 1.0
So, it didn't create correctly; try again - check these links or waht youtube video
It should be like that:

Manifest-Version: 1.0
Main-Class: JarExample

see:
http://www.astahost.com/info.php/Creating-Executable-Jar-Files_t12219.html
Do you have your project running in Eclipse as Application, - do you have configure Run configuration ?
When I open Run-> Run Configurations,
It has the right project name and right main class.
Try to recreate it - say you can do as in the video or as recommende in stackoverflow question
I did just as shown in the video!
Except for the fact that I'm using a different version of Eclipse - Galilieo.
I just did it with one of my projects and got manifest.mf like that:

Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: Outer
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

Open in new window

I think it is OK
I have Helios, but don't think it should be different
Now, it says "Cannot find the main class" when I try to run the jar.
Did you go to Run As
select the project and the main class, then said Apply

Then you go to Export, selecte Runnable jar, then go to  Next  sleect configuration and select the file name and folder for the jar
But if you don't have specification of Main class in your manifest it would scertalinly say so
Now I do have the specification.
It says:

Manifest-Version: 1.0
Main-Class: com.HealthMonitor.Monitor
do you have such class in the appropriate folder ?

do yiou run it with

java -jar YourJarName.jar
Yes. It still says "Cannot find main class".
Does it run in Ecliopse?
Yes!
Run As -> Java Application works perfectly.
Try to do the same with some very simple project

Which java are you using on the comman line?
When I type "java -version", i get
1.6.0_20
Try to create non-executable jar from your procject and make sure it runs
when you reference you main class directly on the command line
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is the exact error message:

Does it look like this:

Could not find the main class: <something> Program will exit.

If so, what is <something> ?
I tried the steps you mentioned. Now, when I double click the .jar file, nothing happens.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I meant

java -jar YourJar.jar
Thanks a ton!
Great!