Results 1 to 4 of 4
  1. #1
    s0meb0dy is offline Member
    Join Date
    Sep 2010
    Posts
    42
    Rep Power
    0

    Default How do I run my program through Command Line?

    I'm trying to get my program to run through Command Line or DOS(same thing). I also wanted to create a shortcut that would always run it. I could copy the shortcut w/ the source code or JAR file and run it somewhere else just by clicking the shortcut.

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    call the class that contains the main() method. do execute this class from the command line use

    java ClassName

    without its extension.

  3. #3
    s0meb0dy is offline Member
    Join Date
    Sep 2010
    Posts
    42
    Rep Power
    0

    Default

    error message:

    Exception in thread "main" java.lang.NoClassDefFoundError: DifA
    Caused by: java.lang.ClassNotFoundException: DifAnalysis
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native M
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown S
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: DifAnalysis. Program will exit.

  4. #4
    jac0117 is offline Member
    Join Date
    Jan 2008
    Posts
    9
    Rep Power
    0

    Default

    You have to compile the class that contains the main method.

    javac MyClass.java

    Then you run the class

    java MyClass

    You have to make sure that your environment variable is set up correctly also. If you're on Linux your terminal should have it set up by default already.
    If you are on Windows, it should be something like:
    Control Panel -> System -> Properties -> Environment Variables

    Then your java path should be the java root directory. something like
    c://program files/java_version

    Then add Java Path to your path variable: %Java Path%/bin

    The directions for the path set up are not 100% correct, but if this is your problem just let me know

Similar Threads

  1. can i run line by line command in netbean?
    By choconlongxu in forum NetBeans
    Replies: 1
    Last Post: 07-19-2010, 08:41 PM
  2. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  3. Replies: 14
    Last Post: 01-21-2010, 09:10 AM
  4. Calling a JFrame window from a command line program.
    By new_2_java in forum New To Java
    Replies: 7
    Last Post: 11-09-2008, 03:40 AM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

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