Build java Application

Build java Application

Page 1 of 1

2 Replies - 1558 Views - Last Post: 04 January 2008 - 12:30 PM Rate Topic: -----

#1 yannick  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-October 07

Build java Application

Post icon  Posted 04 January 2008 - 05:20 AM

Hi,
I would like to know how to build a java application, create a jar file.

Thanks,
Yannick :)
Is This A Good Question/Topic? 0
  • +

Replies To: Build java Application

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Build java Application

Posted 04 January 2008 - 06:15 AM

Start here
The NetBeans trail will create a jar as well, and it will also tell you on the console how to run it from the command line.
If you want to create a jar yourself, simply run the jar command from the command line, it will show you the usage information.
Was This Post Helpful? 0
  • +
  • -

#3 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: Build java Application

Posted 04 January 2008 - 12:30 PM

Many IDE's support creation of jar files.

However if your's doesn't, or you don't use an IDE, you can make a jar file from the command line easy enough.

The only command we're going to be using is "jar". If you get a command not found error, or something similar, then either your $PATH variable is not set correctly (%PATH% in Windows I think), or you don't have the JDK installed. You can also manually specify where "jar" is by adding "C:\Java 1.6\bin\" before the command (adjust to where your JDK is installed).

First off, you need to make a "manifest" file. This basically tells the computer what class to run when the jar file is opened.

A manifest file can be named anything, but for clarity we're going to name ours manifest.txt.

In it should be the text Main-Class: main, where main is replaced with the name of the class that contains your "public static void main()" method (don't include ".class" or ".java").

Next you need to compile your program. Move all of the ".class" files into the current directory.

To build the jar file, do the command jar cmf manifest.txt name_of_jar.jar *.class, where "name_of_jar" is whatever you want.

You should now be able to run the jar file by clicking on it, or running it in the command line (java -jar jarfile.jar, IIRC).

Hope that was clear enough, I haven't done much with Java lately. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1