LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Running Java Class Files (https://www.linuxquestions.org/questions/programming-9/running-java-class-files-78856/)

hackersapien 08-04-2003 09:22 AM

Running Java Class Files
 
Hi!Guys,
I downloaded the latest Java SDK and installed it in my /usr/downloads folder without any problems.When I make my java file I compile it without any problems but when I try to run it with the java HelloWorld.java command I get a "class not found" error what could be the problem.

Anybody got any ideas post them here

Looking_Lost 08-04-2003 09:58 AM

Easy mistake to make when starting out

compile the program

javac HelloWorld.java

to actually run the program

java HelloWorld

You won't need to worry about classpath or anything for now as long you run it from the actual directory it was compiled in

moeminhtun 08-04-2003 08:37 PM

Yeap!

To run, Don't put ".java".

hackersapien 08-05-2003 01:14 AM

I know that to run a java class you don't put ".java" I've already programmed in java but in the windows environment.I'm guessing that the class cannot be found coz even in windows when try running a class file that doesn't exist you get an error that goes like this:

"Exception in thread "main" java.lang.NoClassDefFoundError:"
which is the error I'm getting yet the class file exists in my Linux environment.

Got any ideas,post them here.

Looking_Lost 08-05-2003 01:41 AM

Only thing I can think of if you are in the same directory and have compiled it okay is you have named the actual filename.java differently from the class that it holds

ie. you've saved it as MyClass.java

when the actual class has been defined as

public myclass
{

}

sort of thing, or named it something completely different

JeffHervouet 08-06-2003 10:05 AM

Hi all :)

How do I know what version of Java is installed on my Red Hat 8 ?


How do I replace it with a newer version (what do i remove, what variable do I change, how to install the new sdk and where will it be on the HDA)


I have tried to import the awt class, it compiles.
But if I import swing, this can t be found.

Thanks :)

:newbie:

moeminhtun 08-06-2003 10:34 AM

To check Java version, type

java -version


To remove java.

How did you installed? RPM or self-extracting.
If rpm, just use the normal rpm uninstall method.
If self-extraction, just delete the directory, that's it.

I recommand you use self-extraction package.
You can choose to download rpm or self-extraction on the sun website.
It's easier and it can easily put the directory wherever you want, just as a standalone. And give the PATH to the "YourJDKDirectory/bin".
And it can easily co-exist with several version. You don't need to remove the old version. Just put the new one beside and change the PATH, that's it.


To import swing, swing is in the "javax" package. Not in the "java" package.
Like this.

import javax.swing.*

hackersapien 08-07-2003 02:37 AM

Hi!,
I know that in windows you set the environment variable so that you can compile and run java apps from any directory,Can the same thing be done in Linux?
If it can like share it with guys like me who are trying to shake off the addiction to windows

Cheers

julienp 08-07-2003 04:42 AM

You have to set your PATH env. variable to include the Java binaries. To see your current path type "echo $PATH" in a terminal, to add Java, type "export PATH=$PATH:/your/path/to/java/bin" or add the line to your ~/.bashrc

acjt 08-07-2003 06:42 AM

You should also make sure that you have your $CLASSPATH variable set before you run, and that this contains the path to both the java classes (rt.jar) and to your own classes.

Remember compiling and running apps depend on different environment variables.
$PATH simply lets you execute the java binaries from any location, however $CLASSPATH tells the Java VM where to look for the classes to execute.


All times are GMT -5. The time now is 12:13 AM.