[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Build executable jar

Posted on 2011-10-13
36
Medium Priority
?
309 Views
Last Modified: 2012-05-12
Please let me know how I can build an executable .jar out of my project.

Thanks!
0
Comment
Question by:dshrenik
  • 23
  • 13
36 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36965929
Are you using some IDE ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965931
0
 

Author Comment

by:dshrenik
ID: 36965932
I am using Eclipse.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 47

Expert Comment

by:for_yan
ID: 36965940
You'll find in that link above even two ways - one is in the question itself - another is inthe answer
0
 

Author Comment

by:dshrenik
ID: 36965943
I get this error when I try to run thecreated .jar:
Failed to load Main-Class manifest attribute
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965944
and this is even youtibe tutoarila
http://www.youtube.com/watch?v=Czmc2-hSBuk
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965947
wellcopy this .jar to .zip - unzip it and check if you have manifest.mf file and if it syas waht is your main class
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965949
If not, try to recreate it jar again
0
 

Author Comment

by:dshrenik
ID: 36965951
It has just this info:

Manifest-Version: 1.0
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965954
So, it didn't create correctly; try again - check these links or waht youtube video
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965957
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965959
Do you have your project running in Eclipse as Application, - do you have configure Run configuration ?
0
 

Author Comment

by:dshrenik
ID: 36965966
When I open Run-> Run Configurations,
It has the right project name and right main class.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965972
Try to recreate it - say you can do as in the video or as recommende in stackoverflow question
0
 

Author Comment

by:dshrenik
ID: 36965974
I did just as shown in the video!
Except for the fact that I'm using a different version of Eclipse - Galilieo.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965979
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
0
 

Author Comment

by:dshrenik
ID: 36965981
Now, it says "Cannot find the main class" when I try to run the jar.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965982
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965983
But if you don't have specification of Main class in your manifest it would scertalinly say so
0
 

Author Comment

by:dshrenik
ID: 36965986
Now I do have the specification.
It says:

Manifest-Version: 1.0
Main-Class: com.HealthMonitor.Monitor
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965988
do you have such class in the appropriate folder ?

do yiou run it with

java -jar YourJarName.jar
0
 

Author Comment

by:dshrenik
ID: 36965991
Yes. It still says "Cannot find main class".
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36965996
Does it run in Ecliopse?
0
 

Author Comment

by:dshrenik
ID: 36966001
Yes!
0
 

Author Comment

by:dshrenik
ID: 36966003
Run As -> Java Application works perfectly.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36966010
Try to do the same with some very simple project

Which java are you using on the comman line?
0
 

Author Comment

by:dshrenik
ID: 36966013
When I type "java -version", i get
1.6.0_20
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36966064
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
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36966096



in here
https://bugs.eclipse.org/bugs/show_bug.cgi?id=219530

 I read:

Steps To Reproduce:
1. File > Export > Java/Runnable JAR File
2. Wizard Page "Runnable JAR File Specification" shows up
3. Enhancement: new checkbox "use Jar-in-Jar Classloader" appears

Do you have a checkbox  "use Jar-in-Jar Classloader"  in Runnable JAR File Specification screen ?

I do not have such box, but
my Eclipse by fdefault creates this jar-in-jar, yours does not create it, just
wrirtes Main-class. Still should work, but if you happen to have this
checkbox, maybe you want to use it





0
 
LVL 47

Expert Comment

by:for_yan
ID: 36966154
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> ?
0
 

Author Comment

by:dshrenik
ID: 36966198
I tried the steps you mentioned. Now, when I double click the .jar file, nothing happens.
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 2000 total points
ID: 36966217
I normamly not double-click jar

I go to command libne and type there

java -jar YourClass.jar

does it workm this way?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36966220
I meant

java -jar YourJar.jar
0
 

Author Comment

by:dshrenik
ID: 36966230
Thanks a ton!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36966247
Great!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question