Results 1 to 4 of 4
  1. #1
    LongTTH is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Question cant use Command Prompt to run Java App (with screenshot)

    Just HelloWorld "application" like this
    the .java file is in C:\Examples\je3\basics
    PHP Code:
    package je3.basics;                           
    public class Hello {                         
        public static void main(String[  ] args) {  
            System.out.println("Hello World!"); 
        }                                       
    }
    when I jump into that folder and use javac to complie, it's OK.

    but when I use java to run it:

    even I've try changing the path to the .class file. It's still not OK

    this is my java version and javac version:

    My Environment Variables:
    CLASSPATH and JAVA_HOME:
    Java Code:
    .;%JAVA_HOME%;
    Java Code:
    C:\Program Files\Java\jdk1.6.0_25
    Path

    -
    event I can use Eclipse or other IDE to run it. I really do want to know how to do it (run my little HelloWorld app just with JDK and Command Prompt).

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    You've defined your class to be within a package, so compile and run the class(es) from the root of the package (eg cd up to the Examples directory, then javac (or java) the class from there je3/basics/Hello
    See Creating and Using Packages (The Java™ Tutorials > Learning the Java Language > Packages)

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,765
    Blog Entries
    7
    Rep Power
    21

    Default

    ... or alternatively, don't specify a package for the class; I don't recommend this option because you are going to meet the troubles of packages later again, but it is a quick fix/hack for now.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    LongTTH is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Thumbs up

    Quote Originally Posted by doWhile View Post
    You've defined your class to be within a package, so compile and run the class(es) from the root of the package (eg cd up to the Examples directory, then javac (or java) the class from there je3/basics/Hello
    See Creating and Using Packages (The Java™ Tutorials > Learning the Java Language > Packages)
    Yeah, it works now

    thanks so much

Similar Threads

  1. how to make command prompt in java
    By udinulis in forum Java 2D
    Replies: 4
    Last Post: 07-14-2010, 07:52 AM
  2. running command prompt using java
    By xclaim in forum New To Java
    Replies: 1
    Last Post: 01-14-2010, 04:46 AM
  3. Command Prompt Java
    By kelvinsmj in forum New To Java
    Replies: 8
    Last Post: 11-27-2009, 11:30 AM
  4. Replies: 2
    Last Post: 12-03-2008, 02:24 PM
  5. accessing command prompt using java (netbeans)...
    By kureikougaiji in forum New To Java
    Replies: 6
    Last Post: 06-27-2008, 04:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •