Help - Search - Members - Calendar
Full Version: Executing a Java program
Hydrogenaudio Forums > Misc. > Off-Topic
Teqnilogik
Okay, first I would like to say that I am new to Java programming. I am taking a class on it in college and I really like the language. I love the "write once, run anywhere" philosophy behind it.

I have been looking at tutorials on http://java.sun.com and the only way I have found to run a compiled Java application is to go to the command line and type in:

java ProgramName.java

I then got curious to how other Java programs operated and so I downloaded one called Jlgui Player which is a Java audio player. I noticed that this program uses executable JAR files. What is a JAR file? I know that it is some type of compression file like Zip but for Java does it also act like an EXE file?

Another thing I noticed was with the NetBeans 3.6 IDE, in the start menu it links to a runidew.exe file in the NetBeans3.6 program files directory. I wasn't aware that you could make EXE files when compiling a Java program or even use EXE files with Java programs. All my compiled programs come out to be a .java file.

I guess my question finally is, what is the best way to create a user friendly Java program that a person can just double-click on a JAR or EXE file and have the Java program run rather than having to go through the command line. The second part of the question is how do I create a JAR or EXE file to use with my Java program?

Thanks for all replies in advance smile.gif
Latexxx
Actually, JAR files are just zip files with some additional information (you can open them using winzip). You can create jar files using a tool called jar! See http://java.sun.com/j2se/1.4.2/docs/tooldo...indows/jar.html . biggrin.gif Jar files act like executable files because installing runtime evironment registers .jar files to javaw.exe which handles the execution. If you don't want to bother to use jar.exe, you can create jar files using NetBeans (I recommend 4.0 beta version).
Teqnilogik
Thanks for the reply. Now I have another problem. I can't seem to run my class file outside of Netbeans. My programs works fine when executed in Netbeans but when I try execute it from the command line it will not run. The errors I get are as follows:

with java.exe:
Exception in thread "main" java.lang.NoClassDefFoundError: Assignment1/class

with javaw.exe:
Could not find the main class. Program will exit.

What's the problem?
ErikS
QUOTE(Teqnilogik @ Sep 12 2004, 08:30 PM)
Thanks for the reply.  Now I have another problem.  I can't seem to run my class file outside of Netbeans.  My programs works fine when executed in Netbeans but when I try execute it from the command line it will not run.  The errors I get are as follows:

with java.exe:
Exception in thread "main" java.lang.NoClassDefFoundError: Assignment1/class

with javaw.exe:
Could not find the main class.  Program will exit.

What's the problem?
*


Try "java Assignment1" for command instead of "java Assignment1.class"...
Teqnilogik
Thanks, ErikS. That works for me.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.