dshrenik
asked on
Build executable jar
Please let me know how I can build an executable .jar out of my project.
Thanks!
Thanks!
Are you using some IDE ?
This is how you do it in NetBeans
http://dr.berkeley.edu/REM/wiki/index.php/Making_a_Java_executable_jar_in_Netbeans
http://dr.berkeley.edu/REM/wiki/index.php/Making_a_Java_executable_jar_in_Netbeans
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
ASKER
I get this error when I try to run thecreated .jar:
Failed to load Main-Class manifest attribute
Failed to load Main-Class manifest attribute
and this is even youtibe tutoarila
http://www.youtube.com/watch?v=Czmc2-hSBuk
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
ASKER
It has just this info:
Manifest-Version: 1.0
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
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 ?
ASKER
When I open Run-> Run Configurations,
It has the right project name and right main class.
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
ASKER
I did just as shown in the video!
Except for the fact that I'm using a different version of Eclipse - Galilieo.
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:
I have Helios, but don't think it should be different
Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: Outer
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
I think it is OKI have Helios, but don't think it should be different
ASKER
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
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
ASKER
Now I do have the specification.
It says:
Manifest-Version: 1.0
Main-Class: com.HealthMonitor.Monitor
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
do yiou run it with
java -jar YourJarName.jar
ASKER
Yes. It still says "Cannot find main class".
Does it run in Ecliopse?
ASKER
Yes!
ASKER
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?
Which java are you using on the comman line?
ASKER
When I type "java -version", i get
1.6.0_20
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
when you reference you main class directly on the command line
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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> ?
Does it look like this:
Could not find the main class: <something> Program will exit.
If so, what is <something> ?
ASKER
I tried the steps you mentioned. Now, when I double click the .jar file, nothing happens.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I meant
java -jar YourJar.jar
java -jar YourJar.jar
ASKER
Thanks a ton!
Great!