**HELP Please** quick question on: Java, BlueJ problem, .JAR File

snowman15

Solid State Member
Messages
16
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?
Help!
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!
Tom
 
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.
 
Back
Top Bottom