Menu

Run... arguments for java in Windows

iguessnot
2005-11-04
2012-11-13
  • iguessnot

    iguessnot - 2005-11-04

    I don't know if anyone has posted this already or would even like this, but I found it useful to do this.

    Basically, these are cmd (windows batch files) for command line compiling in java. (You need to have the JDK installed.)

    1)Copy the code inside the ***s as the given file name in your C:\ drive

    ***************Save this as javac.cmd
    @echo off
    title javac %2
    echo compiling %2
    @cd %1
    javac %2
    echo compile complete...
    @pause
    ******************************************

    ***************Save this as javadoc.cmd
    @echo off
    title javadoc %2
    echo compiling %2
    @cd %1
    javadoc %2
    @pause
    *********************************************

    ********************Save this as java.cmd
    @echo off
    title java %2
    @cd %1
    java %~n2
    @pause

    ***********************************************
    2) create these Run... commands within notepad++ (feel free to save them and map them to keys - I use F5, F6, and F7, respectively.

    C:\javac.cmd "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"
    C:\javadoc.cmd "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"
    C:\java.cmd "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"

    3) You're done! Now you have a light, fast Notepad++-driven Java IDE.

     
    • Nobody/Anonymous

      But the java command doesn't work for the .java source code,... Only for the .class bytecode that the .javac command generates...

      I tried what you said assuming you know more than I do, but nothing seemed to happen when I executed them from Notepad++...

      Can somebody explain in more noob terms, please?

       
      • ytbau

        ytbau - 2007-09-03

        Thank you for iguessnot posting.

        Just to let you know that I had successfully configure by javac(F8) and java(F9) to port my Crimson Editor v3.70 setting to Notepad++ v4.2.2.

        Below is my reply oneweb.

        As we know that to compile Hello.java file, we type the following command in the windows command prompt:

        javac Hello.java

        Then, Hello.class java bytecode file will be generated by the java compiler. To run this Hello.class file, we type the following command:

        java Hello

        Therefore, what the "java %~n2" command actually means is that we java/run the baseName of second argument in C:\java.cmd "$(CURRENT_DIRECTORY)" "$(FILE_NAME)". The "$(FILE_NAME)" or Hello.java is the second argument but the basename(%~n2) of the second argument is "Hello".

        Hope this help.

        Reference:
        1. http://www.student.oulu.fi/~vtatila/batch_tutorial.html

        Samples to test:

        // Hello.java
        public class Hello {

            public static void main( String args[] ) {
           
                System.out.printf("IBM Annual Code Match 2008%n");
           
            }
           
        }

        //c:\javac.cmd
        // :: means comment in MSDOS Batch Programming
        // @ means batch display suppression operator eg @<command>
        :: My Javac
        @echo off
        @cd %1
        javac %2
        echo compile completed.
        @pause

        //c:\java.cmd
        @echo off
        @cd %1
        java %~n2
        @pause

        // create these Run... commands within notepad++
        // (save them and map them to keys - I use F8(javac) and F9(java),
        // respectively because of my previous Crimson Editor setting
        C:\javac.cmd "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"
        C:\java.cmd "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"

        // just in case you want to edit your run setting, you may configure it from
        // C:\Documents and Settings\ytbau\Application Data\Notepad++\shortcuts.xml

         
    • Nobody/Anonymous

      Thanks very much! Just what I needed at the time...

       
    • -

      - - 2006-03-03

      I could be wrong but javac compiles the .source into a .class which the java command can run.

      What does the %~n2 specify though?