Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create JAR files

 
Carlos Delgado
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all! I'm very newbie in Java. I got to do an application for my school where my teacher haven't teached us very well.
My application is finished but I want to know how to create a JAR file.
Is a JAR file an executable file? What's a manifest file?
I've got a main Swing form, several classes, a folder where I put the exception classes and another folder with images (gif).
I've searched in this forum but all questions about this are too complicated to me. I don't want a complicated one, just knowing how to do a simple one.
Thanks in advance!

(Sorry for my english. I'm spanish.)
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look here
http://java.sun.com/docs/books/tutorial/jar/basics/index.html

Lots of answers can generally be found at Sun's java Tutorials & Code Camps area: http://java.sun.com/docs/books/tutorial/index.html
 
Chandra Sekhar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The command to create jar file is

jar cvf <jarfilename> folder containing class files/*.*

ex: jar cvf ranch.jar ranchsrcs/*.*

this will also create a manifest file automatically.

U can make jar file executable,ie when u double click on jar to run ur application,u need to give the class name contains main method in ur manifest file.

Edit the manifest file add an entry like
Main-Class: classname

Chandrasekhar
SCJP
 
Carlos Delgado
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS!!!
I've got this code in a BAT file:

I've got a folder with GIFs called "graficos" and another with the Exceptions called "errors".
As the command JAR creates the MANIFEST but not create the Main Class automatically I've got the external "MANIFEST.MF" with:

which is my main Swing class.
Is all OK?
Thanks again!
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,in the manifest you write
the name of the class that contains the main
method. in ur case : formulario
watch out for the spaces
 
Carlos Delgado
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by omar bili:
hi ,in the manifest you write
the name of the class that contains the main
method. in ur case : formulario
watch out for the spaces


Are you meaning that "Main-Class: formulario" should be wrong? Should it be "Main-Class:formulario"?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carlos, are you still stuck?

You might like to take a look at the Creating an Executable JAR File thread.
 
Carlos Delgado
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
Carlos, are you still stuck?

No, thanks Dirk. I've already made what I needed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic