Compiling and Running Java Source Files Using EditPlus Tools

上一篇 / 下一篇  2011-12-31 11:41:27

There is a way to compile and run your Java source code files without using the command prompt! You can set up some menu options in EditPlus that allow you to quickly compile and run your Java programs. You might want to print these instructions so you can follow these steps. Later we will add a tool or two to this group, so make sure you keep or bookmark these instructions.

Setting up the Tools

Open up EditPlus. It doesn't matter if you have a new/existing document open or not.

To follow these instructions, you need to know the drive and path where you installed your Java SDK. If you followed the default settings, this is probably c:\jdk1.5.0 or c:\Program Files\jdk1.5.0. If you have a different version of the Java SDK, then the folder name might vary slightly. It doesn't matter what it's called, as long as it contains the "bin" folder with all the SDK utilities. In the instructions, this folder will be referred to as theJava SDK folder.

  1. Select "Configure User Tools" from the "Tools" menu.
  2. You'll see "Groups and Tool Items" in the middle of the dialog box. Tool groups allow you to organize the different tools you want to create and maintain in EditPlus. We are going to create a tool group called "Java Tools".

      tools dialog box

      1. You should see a dialog box like the image shown here. The default group name will probably be "Group 1". To change it, click on theGroup Namebutton.
      2. In the New Name text box, typeJava Tools
      3. Click OK.
      4. You should now see "Java Tools" in the pull-down box under the caption "Groups and Tool Items"
    • Now you need to add some tools to your tool group. We'll start with a tool used to compile Java Source code files. If you don't have the Configure User Tools dialog box open, follow step 1 above.
      1. Click theAdd Tool>>>button and selectProgramfrom the pop-up menu.
      2. In the Menu Text field, type "Compile Java Source". This is the text you will see in the menu for this tool.
      3. Select the program that will run when you select the "Compile Java Source" menu item: Click the small button to the right of the "Command" field.
      4. Browse to your Java SDK folder and go into the "bin" subfolder. Find and select the file calledJAVAC.EXE. Make sure you select the right file - there are a lot of files in this folder and they have similar names. When you're sure you have the right file, click Open. You should see the path and file information in the "Command" field. Of course you could type this in by hand instead of using the Browse button if you wanted to.
      5. When you run the Java compiler, you always give it the name of the source file as an argument. We can set this up for this tool: Click the button to the right of the "Argument" field and select File Name. You should see $(FileName) appear in the field.
      6. If you are using Java SDK 1.5 or higher, type-Xlint, followed by a space, in front of $(FileName).
      7. Click the button beside the "Initial Directory" field and selectFile Directory. You should see $(FileDir) appear in the field. This ensures that your compiler runs as if it were in the same folder as your Java source file.
      8. Lastly, check off the box forCapture Output. This will show the output to your compile in a small window at the bottom of the screen. If you prefer that the output show up in a larger command-prompt window, do not check this option.
      9. Click theApplybutton to save your tool changes.

      When finished, your dialog box should look like this one:

      dialog box after setup

    • The next tool we need to add is for running our Java class files. Again, if you aren't in the configure user tools dialog box, follow step 1 above.
      1. Click theAdd Tool>>>button and selectProgramfrom the pop-up menu.

      2. In the Menu Text field, type Run Java Class. This is the text you will see in the menu for this tool.

      3. Select the program that will run when you select the "Run Java Class" menu item: Click the small button to the right of the "Command" field.

      4. Browse to your Java SDK's /bin folder and select the file calledJAVA.EXE. Double check to make sure you have the right file selected, then click Open. You should see the path and file information in the "Command" field.

      5. When you use the JAVA command to run a Java class file, you always specify the name of the class file without the extension. We can set this up for this tool: Click the button to the right of the "Argument" field and select File Name without Extension. You should see $(FileNameNoExt) appear in the field.

      6. Click the button beside the "Initial Directory" field and select File Directory. You should see $(FileDir) appear in the field. This ensures that the java command interpreter runs as if it were in the same folder as your Java class file.

      7. Lastly, check off the box forCapture Output. This will show the output of your program (if any) in the same output window where you see the output to the compile process. If you would rather see the output in a command-prompt window, leave this option unchecked.

      8. Click the Apply button to save your tool changes.
    To run a program using command-line arguments, set up a new tool menu just like the one in step 3, but make sure you check off the box labeled "Prompt for Arguments". This will cause a dialog box to appear where you can type your command-line arguments (in the exact same format you would type them at the Dos prompt).

    You could also check off this box in the tool menu item you created in step 3, and when you run a program that does not require arguments, click the "Skip" button in the arguments dialog.


    Dialog box with Run with Arguments settings


    Dialog box with Run settings

    Using the Tools

    To compile, go to the EditPlus window with the source file you want to compile and select "Compile Java Source" from the Tools menu. If you prefer using the keyboard, you can also compile the current program by pressing the Ctrl-1 keys.

    To run a class file, go to the EditPlus window with the source file you want to run (rather, the source file that is associated with the class file you want to run), and select "Run Java Class" from the Tools menu. If you prefer using the keyboard, you can also run the class file by pressing the Ctrl-2 keys.

    Note that the keyboard shortcuts may vary if you have already created user tools. You can see what shortcut keys are associated with your tools by looking at your tool menu items in the Tools menu.

    Other Important Notes

    Note that sometimes when you compile Java source files and you get errors, the little caret ^ symbol that points to the spot in the code statement may not necessarily be in the right location. This is probably because of the fonts you are using in the EditPlus program (even if you didn't change the fonts). For the most part this shouldn't be a problem since you will probably know exactly where your error is in the offending statement, but if not, you will have to try compiling your program in DOS instead.

    You can also set up EditPlus to use Appletviewer. The image below shows the settings for the Appletviewer utility:


    Dialog box with Run Applet settings (used on an open HTML file!!)


    TAG:

     

    评分:0

    我来说两句

    Open Toolbar