Menu

Run java

2008-02-20
2012-11-13
  • Nobody/Anonymous

    Here is how to compile and execute Java source files.  This is used under the run command of Notepad++ (hotkey F5).

    Compile command: cmd /c cd "$(CURRENT_DIRECTORY)" && (javac "$(FILE_NAME)" || pause)
    Execute command: cmd /k cd "$(CURRENT_DIRECTORY)" && java "$(NAME_PART)"
    Open CMD: cmd /k cd "$(CURRENT_DIRECTORY)"

    --Additional stuff--

    Here are my entries in shortcuts.xml:
      <Command name="Javac" Ctrl="yes" Alt="no" Shift="no" Key="49">cmd /c cd &quot;$(CURRENT_DIRECTORY)&quot; & javac &quot;$(FILE_NAME)&quot;</Command>
      <Command name="Java" Ctrl="yes" Alt="no" Shift="no" Key="50">cmd /k cd &quot;$(CURRENT_DIRECTORY)&quot; && java &quot;$(NAME_PART)&quot;</Command>
      <Command name="Command Prompt" Ctrl="yes" Alt="no" Shift="no" Key="51">cmd /k cd &quot;$(CURRENT_DIRECTORY)&quot;</Command>

    Note: shortcuts.xml is in Notepad++'s base folder (C:\Program Files\Notepad PP\) or if you're using Notepad++ portable its in ....\Notepad++Portable\Data\settings\.

    Note: Notepad++'s Run can be used to execute CMD commands in the same way I'm showing.  The cmd /c executes the command then terminates.  The /k executes the command then the CMD stays open.
    Here's some info: http://www.ss64.com/nt/cmd.html and http://commandwindows.com/command1.htm

    Also note: If the java or javac commands aren't recognized in the command prompt this is because java/javac isn't set under environment variables (Located under MyComputer>Properties>AdvancedTab>EnvironmentVariablesButton) and so CMD doesn't know where to find these programs (java.exe/javac.exe).  I'm pretty sure that's right.. try google-ing "java javac environment variables" for more info.

    Hope this helps. GL.

    -Steven R / TOAST

     
    • Nobody/Anonymous

      Arg, scratch last post:
      <Command name="Javac" Ctrl="yes" Alt="no" Shift="no" Key="49">cmd /c cd &quot;$(CURRENT_DIRECTORY)&quot; && (javac &quot;$(FILE_NAME)&quot; || pause)</Command>

       
    • Nobody/Anonymous

      I forgot to update one of the commands.. in the shortcuts.xml it should read:
      <Command name="Javac" Ctrl="yes" Alt="no" Shift="no" Key="49">cmd /c cd &quot;$(CURRENT_DIRECTORY)&quot; & javac &quot;$(FILE_NAME)&quot;</Command>

      The update is to pause when an error occurs (such as a compilation error).