Java 1.7.0_03 Error: could not find or load the main class

I just updated to the latest version of Java

> java -version java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b05) Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode) > javac -version javac 1.7.0_03 

I am having problems running a Java program from the command line. For instance:

 public class Tester { public static void main(String[] args) { System.out.println("in main"); } } 

I compiled it on the command line, then try to execute it:

 > javac Tester.java > java Tester Error: Could not find or load main class Tester 

This is mistake? Oddly enough, I have no problem running the program using Eclipse.

+1
source share
5 answers

Is the CLASSPATH environment variable set? When i do

 export CLASSPATH=/tmp java Tester 

I get a NoClassDefFoundError, but not the same error message that you specified.

+2
source

Run jar files in console mode. java -jar filename.jar

+2
source

I had the same error when trying to start Tomcat, and I realized that this was because I was using the 64-bit version of Tomcat on a 32-bit system. As soon as I tried the 32-bit version, it worked.

0
source

if you want to run the program in the current working directory where your class is located.

java provides three options.

first option

Tester java -cp

The second option for the current working directory

java -cp. Tester

The third option exports the CLASSPATH variable

export CLASSPATH = $ CLASSPATH :. (this is the best option if your directory is changing) or

export CLASSPATH = $ PWD

or

export CLASSPATH =

after that you should evaluate bashrc or bashprofile.

0
source

just set your path to system variables:

 classpath=. 
0
source

All Articles