Go Back   Computer Forums > General Computing > Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 03-31-2007, 01:20 PM   #1
Solid State Member
Join Date: Sep 2006
Posts: 9
Default **HELP Please** quick question on: Java, BlueJ problem, .JAR File

Hey everyone, im pretty new to the java scene but I have a really quick question that hopefully someone can help me with.

I'm really interested in making a .jar file out of my code. And basically I just want to make one. but i understand there are certain things like main class's, etc. that need to be made in order to make a .jar file.

So, for instance, say I create a new project.
I create 1 new class called "HelloWorld"
I open that up and type this code:

class HelloWorld {
public static void main (String[] args)
System.out.println("Hello World");

I compile that. But now i want to make a.jar file.

I went to project> create .jar file, and it was made.
but i go into it and it says "cannot find main class"
The only class that i made has the name "main"
is there something im missing?
All i want is to create a jar file that will execute the above code!
I have: 1 class, named "HelloWorld", and the above code, Thats it!

What steps from there do i do to make a jar file and have it be able to be executed and SEE the "hello" printed somewhere NOT in blueJ??

(I understand there is something about a "static" method? Im not really sure but if somoene could enlighten me on how to make a .jar file that would be great.)

Thanks a lot everyone!

snowman15 is offline   Reply With Quote
Old 04-01-2007, 11:32 AM   #2
In Runtime
Daeva's Avatar
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: **HELP Please** quick question on: Java, BlueJ problem, .JAR File

Well, I suppose my question to you is why do you need a .jar file for the hello world application. A .jar file is basically just a zipped java program that groups all the necessary audio/images/packages that are required by the class you wrote. It is also used for streamlined downloading via internet and can be used to restrict access to certain files. Using your current code the only reccomendation I would have is you have to make the class public
in your class header declaration you have:
class HelloWorld {
instead try:
public class HelloWorld {

Also, I assume that you're using blueJ, I am not familiar with this IDE.
If you want to able to just run the java program, you would have to open up the command prompt, and assuming that the necessary java files are installed in your system32 folder, you'd need to do this to access your java program(Also, for java development in strait coding, I reccomend you download the free text-editor Textpad).
open up start menu and go to run
type cmd and press enter
from here, navigate to the folder where your HelloWorld.java file is located
if your .java file is located in the C:\ directory and no other folders you would type this:
cd \
then enter
then type:
javac HelloWorld.java
then enter
that will compile your java program then you type
java HelloWorld
then enter and this will run your program.
if your computer says that this command is not recognized, then your .EXE files name java, and javac are not in the system32 folder. Hope this helps.
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
Daeva is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 10:36 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0