Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Please help me! i am unable to compile and execute java files in command prompt

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help me! i am unable to compile and execute java files in command prompt

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Sunanda>set Path=C:\Program Files\Java\jdk1.7.0_11\bin

    C:\Users\Sunanda>set HomePath=C:\Program Files\Java\jdk1.7.0_11\bin

    C:\Users\Sunanda>javac HelloTest.java
    javac: file not found: HelloTest.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Sunanda>java HelloTest
    Error: Could not find or load main class HelloTest

    C:\Users\Sunanda>javac FirstExample.java
    javac: file not found: FirstExample.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Sunanda>set Path=C:\Program Files\Java\jdk1.7.0_11\bin

    C:\Users\Sunanda>set HomePath=C:\Program Files\Java\jdk1.7.0_11

    C:\Users\Sunanda>javac HelloTest.java
    javac: file not found: HelloTest.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Sunanda>javac -d HelloTest.java
    javac: directory not found: HelloTest.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Sunanda>cd Documents

    C:\Users\Sunanda\Documents>cd NetBeansProjects

    C:\Users\Sunanda\Documents\NetBeansProjects>cd JavaApplication1

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1>set Path=C:\Program
    Files\Java\jdk1.7.0_11\bin

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1>set HomePath=C:\Pro
    gram Files\Java\jdk1.7.0_11

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1>javac HelloTest.jav
    a
    javac: file not found: HelloTest.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1>javac
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are u
    sed
    -classpath <path> Specify where to find user class files and annotati
    on processors
    -cp <path> Specify where to find user class files and annotati
    on processors
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -proc:{none,only} Control whether annotation processing and/or compil
    ation is done.
    -processor <class1>[,<class2>,<class3>...] Names of the annotation processors
    to run; bypasses default discovery process
    -processorpath <path> Specify where to find annotation processors
    -d <directory> Specify where to place generated class files
    -s <directory> Specify where to place generated source files
    -implicit:{none,class} Specify whether or not to generate class files for
    implicitly referenced files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release

    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -Akey[=value] Options to pass to annotation processors
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system
    -Werror Terminate compilation if warnings occur
    @<filename> Read options and filenames from file


    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1>javac -g HelloTest.
    java
    javac: file not found: HelloTest.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1>cd src

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1\src>cd javaapplicat
    ion1

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1\src\javaapplication
    1>javac HelloTest.java

    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1\src\javaapplication
    1>java HelloTest
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloTest (wrong name
    : javaapplication1/HelloTest)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :791)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:14
    2)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:482)


    C:\Users\Sunanda\Documents\NetBeansProjects\JavaAp plication1\src\javaapplication
    1>

    ..................This is the error that i encountered


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Please help me! i am unable to compile and execute java files in command prompt

    javac: file not found: HelloTest.java
    Make sure the file: HelloTest.java is in the folder where you issue the javac command
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    The last attempt it actually compiled, then threw an exception when it was run... Post your source code so we can see what the problem is

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Please help me! i am unable to compile and execute java files in command prompt

    I missed the last error message:
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloTest (wrong name
    : javaapplication1/HelloTest)
    The class in in a package: javaapplication1. The simplest way to get the code to execute is to remove the package statement and compile it again and then execute it.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Why are you compiling at the command prompt anyway? If you're writing the code in netbeans it makes far more sense to build the project from within netbeans...

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Please help me! i am unable to compile and execute java files in command prompt

    Quote Originally Posted by Hammet27 View Post
    Why are you compiling at the command prompt anyway? If you're writing the code in netbeans it makes far more sense to build the project from within netbeans...
    I think it makes sense to learn how to compile and run from the command line even if using an IDE. This understanding *will* be useful and in fact necessary at some point.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by curmudgeon View Post
    I think it makes sense to learn how to compile and run from the command line even if using an IDE. This understanding *will* be useful and in fact necessary at some point.
    Agreed, javac and java commands should be learnt and understood... I would actually recommend starting the learning process with just a text editor (Sublime Text 2, or Notepad++ are good) to write your source and compiling from the command line... Keeps the focus on learning the language instead of "how do I use this damn IDE?"

  8. The Following User Says Thank You to Hammet27 For This Useful Post:

    curmudgeon (March 24th, 2013)

Similar Threads

  1. Implement 2PC Protocol - Unable to Compile and Execute
    By The.Reaper in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 29th, 2012, 06:25 AM
  2. Java program not running in command prompt
    By Padmahasa in forum Computer Support
    Replies: 1
    Last Post: August 10th, 2012, 07:22 AM
  3. Java command prompt
    By Tanmaysinha in forum Java Theory & Questions
    Replies: 2
    Last Post: August 30th, 2011, 09:30 AM
  4. Java command prompt
    By Tanmaysinha in forum Java Theory & Questions
    Replies: 1
    Last Post: August 29th, 2011, 03:05 PM
  5. Java on command prompt
    By Tanmaysinha in forum What's Wrong With My Code?
    Replies: 12
    Last Post: August 17th, 2011, 06:45 AM