Javac command in Command Prompt

When I compile a .java file in Command Prompt I have to write the whole path to javac.exe - "C:\"Program Files"\Java\jdk1.5.0_07\bin\javac.exe PROBLEM.java"
What do I have to do to so I could write just "javac PROBLEM.java" no mather in which directory I am?
I also have to say that I can run java.exe from any directory but I can't do so with javac.exe
Message was edited by:
vedex

I believe the location of "javac" inside jdk must be
specified in systems variable so that he/she can
compile it and run. His problem is that he wants to type javac MyClass.java rather than C:\jdk\bin\javac.exe MyClass.java In order to do this, he has to alter his PATH variable.
This has nothing to do with Java. This is true of any executable you want to run without specifying the full path.

Similar Messages

  • Javac command in windows command prompt

    Hi, i would just like to know how i can enable the javac command in the command prompt of windows without being in the java/bin directory...i have tried env. variables and stuff but to no avail, however the java command work.
    Thanks Rudy
    ps does anyone know any good rmi tutorials which are easy to follow, thanks.

    Err, nm, just reread that.
    The environment Path is the way to go.
    Just add the bin directory to the end of the PATH in the advanced option of my computer. You may need to reboot.

  • I'm new to Java and can't get javac command working

    Ok first of all hello ( i'm new to the forum ), second i'm reading a book about Java and im trying to compile a sample code from the book, but javac command gained life and it's against me. So the book i'm reading is Sams Teach Yourself Java in 21 Days (YAY), and the code i want to compile is an application that works with another bit of code that mimics what a robot could do inside a volcano. So the Volcano program code is the following ( i'll post the robot code at the end of the post):
    1: class VolcanoApp {
    2: public static void main(String[] arguments) {
    3: VolcanoRobot dante = new VolcanoRobot();
    4: dante.status = ?exploring?;
    5: dante.speed = 2;
    6: dante.temperature = 510;
    7:
    8: dante.showAttributes();
    9: System.out.println(?Increasing speed to 3.?);
    10: dante.speed = 3;
    11: dante.showAttributes();
    12: System.out.println(?Changing temperature to 670.?);
    13: dante.temperature = 670;
    14: dante.showAttributes();
    15: System.out.println(?Checking the temperature.?);
    16: dante.checkTemperature();
    17: dante.showAttributes();
    18: }
    19: }
    Ignore the numbers they are used for explaining stuff in the book, and i din't copy the indentation.
    So what i do is that i creat a file with notepad ( no fancy stuff only plain old notepad ) and i copy this code, remove the numbers and make the indents.
    After that i save as .txt file with the apropriate name ( i know it's case sensitive ). After that i open command prompt and write:
    javac VolcanoApp.java
    And it tells me that "javac is not recognized as an internal or external command operable program or batch file".
    I managed to solve that by going to the control panel and by adding to the system variables for my user in the path variable this :
    ;C:\JAVAJDK\bin
    ( C:\JAVAJDK is where JDK is installed)
    And then i modified the system variables like this:
    In the CLASSPATH i entered this .;%JAVA_HOME%\lib\tools.jar
    In JAVA_HOME i entered this C:\JAVAJDK
    Setting the variables like this made the javac error go away but now when i write in command line
    javac VolcanoApp.java
    It gives me this error
    javac: file not found : VolcanoApp.java
    Usage: javac options source files
    use -help for a list of possible options
    And then i read that i can drop my java file directly in the javac file. So i did.
    When i drop my VolcanoApp.java in the javac file it open a command line window and writes a bunch of stuff in like a milisecond and shuts down. And no file is created.
    I wanted to know what was writen in that window so i did it again and took a print screen and pasted it on paint ( it writed so much text that i only got a little bit but enough to see what hapend)
    I read it and in the print screen it said it had 15 errors ( so far ) and then it point the errors with little arrows and there were characters that weren't present in the original code.
    What hapend the compiler added wierd letters?
    SO, my real question is, how the heck do i get javac working and compiling stuff properly?
    Plz help i'm getting mad at this! ; (
    And the code for the "robot":
    1: class VolcanoRobot {
    2: String status;
    3: int speed;
    4: float temperature;
    5:
    6: void checkTemperature() {
    7: if (temperature > 660) {
    8: status = ?returning home?;
    9: speed = 5;
    10: }
    11: }
    12:
    13: void showAttributes() {
    14: System.out.println(?Status: ? + status);
    15: System.out.println(?Speed: ? + speed);
    16: System.out.println(?Temperature: ? + temperature);
    17: }
    18: }
    Again no indents and ignore the numbers. In the book it only said to compile the VolcanoApp.java , and not the VolcanoRobot.java
    Edit:
    I'm using Windows Vista Home Premium 32 bit.
    Edited by: BBlop on Dec 13, 2009 11:29 AM

    guess what it says java file. So yes i'm sure. Sarcasm. Not the best way to encourage a total stranger to help you. Then there's
    Sorry if i wasn't more clear but was that response needed?No it wasn't needed, but I'm not the one asking for help so I have the luxury of not worrying too much about it. It's extremely frustrating trying to drag relevant information out of someone, and makes one less inclined to bother.
    Anyways, there's still nothing in this thread that actually explicitly says "there is a file called VolcanoApp.java in the directory where I'm running javac from" and I really can't be bothered banging my head against the wall any longer. You've made a silly mistake, or a false assumption. We all do it from time to time. My advice is, take a break, go for a walk and re-visit this in a while. You'll probably spot the mistake right away.

  • Running a GUI application without holding command prompt

    Hi there ,
    I have developed a GUI application using Swing. After compiling the same successfully , when I run the same , presently , I am running it like ,
    c:\> java xxx
    where c:\ is the general command prompt on a Windows machine where I can type in my commands like javac or java and xxx is the class file name . Now till I complete using my GUI application and exit from the same , the command prompt will also be there ( and probably displaying the output of my System.out.println ) . So , two sessions are running , one is just the command prompt and another is the actual GUI application.
    How can I avoide this ? e.g. when I type command "notepad" and press enter , notepad is started and the command prompt returns after starting notepad i.e. the notepad and the command prompt are not related now , I can close the command intrepreter and still notepad is running . What should I do to create such a Java GUI application ? Please advice .

    If I understand you correctly this is something that happens in linux also. And I believe that you can solve this by creating to shortcut to this program.
    And the shortcut or link to application will be the command line that you use to run the Java Application.
    i.e.
    java c:\javadir\subjavadir\application.class
    And I believe that this will allow it to run without the command prompt. Just showing the GUI and no additional command prompt window. Freeing the command prompt is something that I don't know how to do in either OS.
    I use the Link To Application method because I ultimately don't need to have multiple windows for one application. Even though it is nice to be able to kill the Application by destroying the command-prompt session (in case your app causes lock-ups during testing).
    Post your results . . . I'm not even sure that I'm being clear at all with my explanation to your question.

  • How can i run javac command in a Servlet?

    I wanna use javac command in a Servlet ,
    but it can not load the tomcat's lib.
    What can i do?

    Try out. But Iam not sure.
    Runtime.getRuntime("Cmd.Exe"). This wiil open the dos prompt.
    Create ouput stream and write in to it.Try to execute key.
    To invoke the enter key , use ascii value of the enter key

  • Running a Program in JDeveloper using Command Prompt

    Hi,
    I downoladed Oracle JDeveloper 10g. I had written a simple java class called Echo. java. I want to run the file using command prompt. My JDK has the following path:
    F:\Sowmya
    My java file has the following path:
    F:\Sowmya\jdev\mywork\1\1\src\pkg1
    So, in order to compile the file, I gave the following command:
    F:\Sowmya\jdk\bin>javac F:\Sowmya\jdev\mywork\1\1\src\pkg1\Echo.java
    It worked and the Echo.class file was created.
    But, when I tried to run the file using the following command,
    F:\Sowmya\jdk\bin>java F:\Sowmya\jdev\mywork\1\1\src\pkg1\Echo
    Iam getting the following error:
    Exception in thread "main" java.lang.NOClassDefFoundError: F:\Sowmya\jdev\mywork\1\1\src\pkg1\Echo
    This didnt work either:
    F:\Sowmya\jdk\bin>java F:\Sowmya\jdev\mywork\1\1\classes\pkg1\Echo
    Iam getting the same error.
    Can any one please help me regarding this.
    Thank you,
    Sowmya.

    Yes, my class contains a main. It runs if I click run in JDeveloper. But, there is no output displayed. The following is the code:
    public class Echo {
    public static void main (String[] args) {
    for (String s: args) {
    System.out.println(s);
    }

  • Running a java application in command prompt

    hi, I'm new to this forum.
    I would like to know what exactly needs to be specified to run a java application in a normal DOS command prompt.
    I know it is something like:
    javaw -classpath .\class GUI.applicationGUI
    where applicationGUI is the main class, right? What else do I need to do, since I have some other non-GUI classes that I need, inside the class folder ?
    Thanks for your time.

    You need to import those classes. And you need to make packages.
    In classes 1, 2 and 3 put:
    package class;
    In class 4 put;
    package class.GUI;
    Then you need to make the connection:
    In classes 1,2 and 3 put:
    import class.GUI.*;
    In class 4 put:
    import class.*;
    Compile each directory separately while in the respective directory. javac *.java
    Then go back to the directory above the directory "class" and run
    java class/GUI/name_of_file_containing_main_method

  • Problem with JUnit Testing from Command Prompt

    Hi There,
    Related Info:
    OS - Windows 7 32 Bit, IDE Used: Eclipse
    I'm using the following command to compile the java file from the command prompt:
    C:\Users\J\Desktop> javac -classpath .:junit.jar check4PrimeTest.java
    I get the error: "package junit.framework does not exist import junit.framework.*;"
    How can i fix this?
    I have downloaded junit from junit.org the 'junit4.10' and extracted in my Java Folder along side jdkjdk1.7.0_03, jre6, jre7.
    I will post my code below for the 'check4PrimeTest.java' file which im trying to test from the command prompt.
    package check4prime;
    // check4PrimeTest.java
    //Imports
    import junit.framework.*;
    public class check4PrimeTest extends TestCase {
         //Initialize a class to work with.
         private check4Prime check4prime = new check4Prime();
         //constructor
         public check4PrimeTest (String name) {
              super(name);
         //Main entry point
         public static void main(String[] args) {
              System.out.println("Starting test...");
              junit.textui.TestRunner.run(suite());
              System.out.println("Test finished...");
         } // end main()
         //Test case 1
         public void testCheckPrime_true() {
              assertTrue(check4prime.primeCheck(3));
         //Test cases 2,3
         public void testCheckPrime_false() {
              assertFalse(check4prime.primeCheck(0));
              assertFalse(check4prime.primeCheck(1000));
         //Test case 7
         public void testCheck4Prime_checkArgs_char_input() {
              try {
                   String [] args= new String[1];
                   args[0]="r";
                   check4prime.checkArgs(args);
                   fail("Should raise an Exception.");
              } catch (Exception success) {
                   //successful test
         } //end testCheck4Prime_checkArgs_char_input()
         //Test case 5
         public void testCheck4Prime_checkArgs_above_upper_bound() {
              try {
                   String [] args= new String[1];
                   args[0]="10001";
                   check4prime.checkArgs(args);
                   fail("Should raise an Exception.");
              } catch (Exception success) {
                   //successful test
         } // end testCheck4Prime_checkArgs_upper_bound()
         //Test case 4
         public void testCheck4Prime_checkArgs_neg_input() {
              try {
                   String [] args= new String[1];
                   args[0]="-1";
                   check4prime.checkArgs(args);
                   fail("Should raise an Exception.");
              } catch (Exception success) {
                   //successful test
         } // end testCheck4Prime_checkArgs_neg_input()
         //Test case 6
         public void testCheck4Prime_checkArgs_2_inputs() {
              try {
                   String [] args= new String[2];
                   args[0]="5";
                   args[1]="99";
                   check4prime.checkArgs(args);
                   fail("Should raise an Exception.");
               } catch (Exception success) {
                   //successful test
         } // end testCheck4Prime_checkArgs_2_inputs
         //Test case 8
         public void testCheck4Prime_checkArgs_0_inputs() {
              try {
                   String [] args= new String[0];
                   check4prime.checkArgs(args);
                   fail("Should raise an Exception.");
              } catch (Exception success) {
                   //successful test
         } // end testCheck4Prime_checkArgs_0_inputs
         //JUnit required method.
         public static Test suite() {
              TestSuite suite = new TestSuite(check4PrimeTest.class);
              return suite;
         } //end suite()
    } //end check4PrimeTestEdited by: 963042 on Oct 3, 2012 8:57 PM
    Edited by: 963042 on Oct 3, 2012 10:07 PM

    963042 wrote:
    C:\Users\J\Desktop> javac -classpath .:junit.jar check4PrimeTest.javaThat's the Linux way to do it. On windows there is a different list separator. Use this:
    javac -cp .;junit.jar check4PrimeTest.java
    And use -cp to save you some typing ;) If you want to incorporate unit testing into your builds I would suggest looking into automating it a little more through tool such as ant, maven, etc.

  • How to compile & run using command prompt

    Hi all,
    I have a java application consisting of 3 packages & a jar file in the following hierarchy:
    -Project
    -classes
    -src
    -package1
    -package2
    -package3
    -file.jar
    The main class exists in package2 and uses classes within file.jar
    I want the steps to compile and execute the project using command prompt in windows such that the generated classes will be saved in the classes directory
    Can anyone help?
    Thanx in advance

    Hey,
    If your source(*.java) files are in src folder and ur currnet directory is project
    and you want all your class files to be classes folder then you can try this :
    c:\project>javac -cp src\file.jar -d classes\ src\*.javaAssuming that your file.jar file is in src folder.
    The above command will set the classpath to src\file.jar (-cp src\file.jar)
    -d classes\ - will generate all your class files with package hierarchy if any into classes directory.
    src\*.java - specifies the files to be compiled.
    Hope this helps.

  • Run in command prompt

    Hi,
    I have a java application project which has a package with my code and one more package generated by web proxy.How can i run this in command prompt.
    Or how can i create an executable jar with all required libraries and everything.

    It's not recognizing javac, probably because you didn't set the PATH.
    PATH="C:\Program Files\Java\jdk1.5.0_12\bin"Adjust it to the location of your bin folder.

  • Command prompt question

    Hi,
    Is it possible to just start the command prompt in a certain directory. ie. my java programs are in the file C:\Java\myprograms. Can I start the command prompt so that its already in that folder?
    Thanks,
    Cam

    As long as you have set the PATH environment variable
    correctly, the operating system will be able to find
    and run an executable file (java.exe, javac.exe, etc)
    from any directory.
    If you need to set the PATH variable, read #5 of the
    Installation Instructions for the version of Java
    that you have installed.o yeah i know all that i just want to start command prompt in the folder where all my projects are stored so i dont have to type a bunch of commands to get to it. im not sure if its even possible but i just thought someone might know...

  • Javafx through command prompt

    Hi,
    untill now i have used NetBeans for developing javafx applications,
    i want to know how to run javafx applications through command prompt.
    what are the requirements?
    which environment variables to be set?
    and commands to compile and run javafx applications?
    thank you.

    There are some detail steps to run your javafx from command line.
    Firstly Create new file with some javafx source code and save them to specific to your Class name . For eg Test.java with package name test
    Let's assume my javafx is inside C:\Program Files\Oracle directory
    I'll tell you in environment of Window:
    Open CMD
    Let's assume you are in right directory
    set JAVAFX_LIB = C:\Program Files\Oracle\rt\lib\jfxrt.jar
    javac -cp "%JAVAFX_LIB%" -d . Test.javaNow goto directory of javafx sdk/bin . There must be javafxpackager.exe
    javafxpackager -createjar -srcdir <your src dir> -appclass test.Test -outfile <your file name>.jar -outdir <your output dir>Now run the jar file . It will run great.
    Thanks
    Narayan

  • Compiling via the command prompt?

    Hi, I need to compile a program via the command prompt, and I need help setting up the windows environmental variables. I have followed multiple online tutorials on how to do this, but I keep getting the classDefNotFound exception. Can somebody please tell me which variables I should set? Thanks.

    since you are getting a java error, you don't need to change your PATH. All what remains is your CLASSPATH variable. Let's say you have created a directory c:\classes and you store all your classes in subdirectories according to their package. Then your CLASSPATH would like like this:
    .;c:\classes
    Note the dot at the beginning, that means "current directory", so the directory where you invoke java/javac is also part of the classpath. Note also that each item in the classpath is seperated with a ; .
    If you need to add jars to the classpath, don't add the directory containing the jars but add the jars themselves.
    .;c:\classes;c:\jar\yourjar.jar;c:\jar\otherjar.jar
    Hope that helps.

  • Runtime.exec() I need to run a command prompt command from java.

    the code i have that doesn't seem to work is:
    String driveloc = System.getProperty("user.dir").substring( 0, 1 );
            String path = jTextFieldPath.getText();
            String path2 = jTextFieldPath.getText().substring(0, jTextFieldPath.getText().length()-3) + "lst";
            String[] cmd = { "cmd.exe", "/" + driveloc, "ASMtools\\AS11 " + path + " -L >" + path2};
            txt_mf.append( cmd[3] );
            try {
                Process np = Runtime.getRuntime().exec( cmd );
            catch( java.io.IOException ioe) {
                //error
            }jTextFieldPath.getText() contains the path of the file saved by my program.
    the line of code i am trying to run is:
    AS11 FILE1 -L FILE2this line compiles the asm file and converts it to a lst creating an s19 file in the process. AS11 is an exe that aids the command prompt much like javac.
    If you could help me figure this out it would be great.
    Thanks in advance,
    -Juke

    String driveloc =
    System.getProperty("user.dir").substring( 0, 1 );
    String[] cmd = { "cmd.exe", "/" + driveloc,
      "ASMtools\\AS11 " + path + " -L >" + path2};Are you sure you want to invoke cmd.exe with the switch /c or /d or whatever depending on System.getProperty("user.dir") ?
    Starts a new instance of the Windows 2000 command interpreter
    CMD [A | /U] [Q] [D] [E:ON | /E:OFF] [F:ON | /F:OFF] [V:ON | /V:OFF]
        [[S] [C | /K] string]
    /C      Carries out the command specified by string and then terminates
    /K      Carries out the command specified by string but remains
    /S      Modifies the treatment of string after /C or /K (see below)
    /Q      Turns echo off
    /D      Disable execution of AutoRun commands from registry (see below)
    /A      Causes the output of internal commands to a pipe or file to be ANSI
    /U      Causes the output of internal commands to a pipe or file to be
            Unicode
    /T:fg   Sets the foreground/background colors (see COLOR /? for more info)
    /E:ON   Enable command extensions (see below)
    /E:OFF  Disable command extensions (see below)
    /F:ON   Enable file and directory name completion characters (see below)
    /F:OFF  Disable file and directory name completion characters (see below)
    /V:ON   Enable delayed environment variable expansion using c as the
            delimiter. For example, /V:ON would allow !var! to expand the
            variable var at execution time.  The var syntax expands variables
            at input time, which is quite a different thing when inside of a FOR
            loop.
    /V:OFF  Disable delayed environment expansion.

  • Running java from command prompt?

    What do I need to be able to run java code from the command prompt? I have J Builder and when I have questions, mainly people give want me to run from command line. When I do so it says it does not know what javac is.

    javac, java etc.. commands are in the j2sdk\bin directory.
    So you have to give PATH to that bin directory in order to use it in command line. Go to the JBuilder installation folder and look for the j2sdk. (JBuilder comes with the j2sdk but the name may vary)
    If you find it, then give the PATH to it's bin directory.
    Or you can download the j2sdk from sun seperately, and give the PATH to its bin directory.

Maybe you are looking for