Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Creating jar files

 
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey there everyone,
When I use jar cvf myjar myprogram.class I get a jar file but when I click on the icon in windows nothing happens. I even put my code into an ide (shhh don't tell anyone) and tried to use its wizard to create an executable jar file. I got the same result. Am I missing something? I want to be able to run my program without installing a jre on a gazillian computers.
Someone enlighten me please.
thx
J
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it helps I get this message when I type java -jar myjar.jar at the command line:
Failed to load Main-Class manifest attribute from myjar.jar
Any thougts?
thx
Jay
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay,
This is because windows does not associate the .jar file extension with any application. (In windows explorer click on the View... menu, then on Options... then go to the File Types tab to see currently recognized file types.) Also, as far as I know, .jar files are basically like .zip files (actually they *are* .zip files... open one in WinZip... ) they just package all your seperate classes, images, and data files together and compress them a bit. The only way to run a Java program w/o the JRE is to compile it to native code... and that way you wouldn't need a different JRE for each type of computer... you would just need a different native compiler for each type of computer. Although if you just want to run your program on one type of computer this would probably be the way to go... I think there may be free native code compilers out there for Mac and Linux, but I don't know of any *free* ones for Windows... ( I know Symantec and Borland have their versions (and MS *may* for J++, I really don't know since I never used their bastardized version of Java), but all these are pretty expensive...) If anyone knows of any free native code compilers for Windows would you please post?
-Nate
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhh... that helped... you need to make a manifest.mf fil... basically copy these lines (between the ----'s... this is just a copy-paste from one of my manifest files) to a plain text file named Manifest.mf and add it to your .jar (replacing CatacombsApplet w/ the name of the main class that runs your program):
------------------------------------
Manifest-Version: 1.0
Created-By: 1.3.0 (Sun Microsystems Inc.)
Name: CatacombsApplet.class
-------------------------------------
Then do a :
jar cvf myjar Manifest.mf myprogram.class
Hope it helps...
-Nate
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nate,
You da Man!! It took some tinkering and I also got some help from this site: http://forum.java.sun.com/read/21910/q_X4o0qFWDBIAAYhy#LR
Now I can send this program via email to anyone I need to and bada bing bada boom!!!
Thanks a ton!
Jay
 
this is supposed to be a surprise, but it smells like a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic