Mr.
Mr.

Reputation: 10142

Java 1.7.0_03 Error: Could not find or load main class

I just upgraded to the latest 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 issues to execute 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

Is this a bug? Strangely, I have no problem to execute the program using Eclipse.

Upvotes: 1

Views: 18330

Answers (5)

Alex Gorbunov
Alex Gorbunov

Reputation: 239

just set your classpath in system variables:

classpath=.

Upvotes: 0

user1651008
user1651008

Reputation: 27

if you want to run program in current working directory where your class reside.

java gives three options.

first option

java -cp Tester

Second option for current working directory

java -cp . Tester

Third option export CLASSPATH variable

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

export CLASSPATH=$PWD

or

export CLASSPATH=

after that you must sorce the bashrc or bashprofile.

Upvotes: 0

gomisha
gomisha

Reputation: 115

I had the same error when trying to run Tomcat and realized it was because I was using a 64 bit version of Tomcat on a 32 bit system. Once I tried the 32 bit version, it worked.

Upvotes: 0

venat0r888
venat0r888

Reputation: 41

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

Upvotes: 2

gsteff
gsteff

Reputation: 4942

Is your CLASSPATH environment variable set? When I do

export CLASSPATH=/tmp
java Tester

I get a NoClassDefFoundError, though not the exact same error message you quoted.

Upvotes: 2

Related Questions