Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] java compiler error

Started by samosa Oct 26, 2002 at 6:19 PM 3 replies 550+ views
Original Post
samosa
samosa
i posted here a few hours ago asking for a java compiler, someone suggested using the jdk, i have currently set it up and im am trying to compile a simple program for a tutorial, here is my code
    
/**
 * The HelloWorldApp class implements an application that
 * displays "Hello World!" to the standard output.
 */
public class HelloWorldApp {
    public static void main(String[] args) {
        // Display "Hello World!"

        System.out.println("Hello World!");
    }
}
    
i try and compile it using teh javac command and i get this error: error:cannot read: HelloWorldApp.java please someone help, thanks in advance EDIT: i also have a question for all you java gurus, does java make .exe files like C++? or does the user have to use a browser to run it or command propmt? ,Matt -= kill one your a murderer, kill thousands your a conquerer =- [edited by - Samosa on October 26, 2002 7:24:15 PM]
-= kill one you're a murderer, kill thousands you're a conquerer =-
samosa
samosa
ok, i solved that problem, as usual with me it was a stupid mistake, but now i get a different error, hopefully someone can help me with it, when i compile it says

exception in thread "main" java.land.NOClassDefFoundError: com/sun/tools/javac/Main

,Matt

-= kill one your a murderer, kill thousands your a conquerer =-
-= kill one you're a murderer, kill thousands you're a conquerer =-
MaximuS_X
MaximuS_X
Your code is fine. You probably don''t have your PATH set correctly. Make sure your PATH includes the jdk\bin directory c:\whateverdirectoryjdkisin\bin . As far as java executables go, I have heard of some tools that are able to create .exe files from java files (not positive though), but I don''t use any so I can''t tell you where to look(GOOGLE). You can always create a JAR file. It is easily distributable as a single file and can be executed by simply double clicking (will work just as long as the user has java runtime installed).
---
c_wraith
c_wraith
It sounds to me as if you''ve done exactly the WRONG thing fixing your first problem.

Let''s go over how java SHOULD be set up. Given your question about .exe files, I''m going to assume you are running under some version of windows.

First, install the jdk. It sounds like you got that part done ok. Make sure that you haven''t messed with anything in the directory it installed. If you have, uninstall it, and install it again. There are very few things in the jdk directory which should be changed, and none which need to be changed when you''re getting started.

Second, make sure you put the jdk\bin directory in your PATH environment variable. That will allow windows to find the commands like java, javac, jar, javaw, javap, javah, etc...

Third, make sure you don''t have a CLASSPATH environment variable set. Some things (like quicktime for windows, for instance) might create one even without your knowledge. No well-written java application requires the CLASSPATH environment variable to function... They specify the class path in other places, like in shell scripts to run the program, or in jar files that the program is packaged in. Having a CLASSPATH variable set is one of the most common problems for beginners using java.

Fourth, if problems continue, post again. However, be sure to include the source code, the exact commands you are trying to run (including the directory you are running them in), and the exact error messages you''re getting. Without all of those, the best we can do is guess.
c_wraith
c_wraith
Oh, I forgot to address the other question you had...

Java, does not, by default, create .exe files. Sun''s javac won''t create them at all. Other compilers may, TowerJ, GCC, and a few other things being the most notable examples.

The standard approach to distributing a java application is to create an executable jar file. This contains all of the classes and other resources your program needs, and can be run fairly easily on most systems.

Double-clicking an executable jar is enough to execute it under Mac OS X and windows (assuming the JRE is properly installed on the windows system.) I''m not sure about linux/unix, and suspect it will be VERY dependent on the exact system settings.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.