Executing a Java application from command line

Discussion in 'Java' started by Sharp Tool, Jul 19, 2005.

  1. Sharp Tool

    Sharp Tool Guest

    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
    Sharp Tool, Jul 19, 2005
    #1
    1. Advertising

  2. Sharp Tool wrote:

    >
    > 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).

    --
    TechBookReport Java http://www.techbookreport.com/JavaIndex.html
    TechBookReport, Jul 19, 2005
    #2
    1. Advertising

  3. Sharp Tool

    Sharp Tool Guest


    > Sharp Tool wrote:
    >
    > >
    > > 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).


    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.
    Sharp Tool, Jul 19, 2005
    #3
  4. Sharp Tool wrote:
    >
    > 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
    --
    Unemployed English Java programmer
    Thomas Hawtin, Jul 19, 2005
    #4
  5. Sharp Tool wrote:
    >>Sharp Tool wrote:
    >>
    >>
    >>>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).

    >
    >
    > 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

    --
    XML is the programmer's duct tape.
    Raymond DeCampo, Jul 19, 2005
    #5
  6. Thomas Weidenfeller, Jul 19, 2005
    #6
  7. Sharp Tool

    Sharp Tool Guest


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

    >
    > http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html
    >
    > > WHAT AM I DOING WRONG?

    >
    > 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
    Sharp Tool, Jul 20, 2005
    #7
  8. On Tue, 19 Jul 2005 23:41:52 GMT, Sharp Tool wrote:

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

    >>

    (Thomas W.)
    >> http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html

    ....
    > 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?

    --
    Andrew Thompson
    physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
    Transmitido en Martian en SAP
    Andrew Thompson, Jul 20, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arun
    Replies:
    4
    Views:
    317
    anonymous
    Jan 3, 2005
  2. Jari Kujansuu
    Replies:
    1
    Views:
    4,884
    Juha Laiho
    Jun 2, 2005
  3. Brad Pears

    Executing a command line applications...

    Brad Pears, Sep 28, 2004, in forum: ASP General
    Replies:
    18
    Views:
    418
    Brad Pears
    Oct 1, 2004
  4. Nick
    Replies:
    14
    Views:
    313
    Tad McClellan
    Oct 3, 2003
  5. Monkey Man

    executing from command line

    Monkey Man, Feb 5, 2004, in forum: Perl Misc
    Replies:
    8
    Views:
    166
    Eric SALGON
    Feb 11, 2004
Loading...

Share This Page