Executing a Java application from command line

S

Sharp Tool

Hi

I'm trying to execute a Java program from the command line.
I have set the path environment variable to point to the following:

- C:\Program files\Java\jre1.5.0_04\bin
- C:\Documents and Settings\Desktop\Java\Test.class

And PathEXT variable to include:

..CLASS
..class
..JAVA
..java

Now when I start ->run->cmd and type at the command line:

Z:\java Test

I get the error: NoClassDefFound
Note: when I run cmd it defaults to Z:\ drive

Also, switching to:

C:\java Test

Gives the same error.

However, if I change directory to point to:
C:\Documents and Settings\Desktop\Java
and type:
C:\Documents and Settings\Desktop\Java\java Test
It works

I have also tried the classpath from C:\
For example:
C:\java -classpath C:\Documents and Settings\Desktop\Java\Test.class
Gives "and" error

WHAT AM I DOING WRONG?

Cheers
Sharp Tool
 
T

TechBookReport

Sharp said:
I have also tried the classpath from C:\
For example:
C:\java -classpath C:\Documents and Settings\Desktop\Java\Test.class
Gives "and" error

Try enclosing the path in quotes, also the class path should be a path
(i.e. it shouldn't include the name of the class file).
 
S

Sharp Tool

Try enclosing the path in quotes, also the class path should be a path
(i.e. it shouldn't include the name of the class file).

OK, but why can't I execute the Java program from Z:\ or C:\ ?
Because I have set the environment variables correctly, and so it should
know where to look for the java.exe and the java class file.

Cheers
Sharp Tool.
 
T

Thomas Hawtin

Sharp said:
OK, but why can't I execute the Java program from Z:\ or C:\ ?
Because I have set the environment variables correctly, and so it should
know where to look for the java.exe and the java class file.

There are two environment variable involved. PATH to pick up java.exe
the binary and CLASSPATH to pick up the class files.

Tom Hawtin
 
R

Raymond DeCampo

Sharp said:
OK, but why can't I execute the Java program from Z:\ or C:\ ?
Because I have set the environment variables correctly, and so it should
know where to look for the java.exe and the java class file.

Not to be rude, but the short answer is because you have not set the
environment variables correctly.

First of all, the PATHEXT variable is meaningless with respect to java.

Secondly, you do not say what your CLASSPATH is set to, although from
what you describe I can intuit that it contains the current directory,
i.e. ".".

The first thing you should do is read some documentation on how to set
the CLASSPATH. One place to start is with the documentation that is
available from Sun for the JDK.

One you understand classpaths, give your program another try.

Ray
 
S

Sharp Tool

You don't know your tools. Oh, and please don't shout at us.

/Thomas

Sorry, I didn't know uppercase means shouting.
I know how to set classpath now.
But I don't know how to set it permantely.
I don't seem to see it in the environment variables anywhere.

Sharp Tool
 
A

Andrew Thompson

....
I know how to set classpath now.
But I don't know how to set it permantely.

What does the URL that Thomas linked to say, about setting the
classpath permanently, in the last sentence of the first paragraph?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top