Compile Java On Mac With TextWrangler

compile Java files on MacTextWrangler is a great free text editor by Bare Bones Software. It provides color-coding for almost every computer language out there, which is extremely helpful for troubleshooting programs and scripts. This article will reveal how to add Java compile and run scripts to TextWrangler, which will allow you to run Java files via the Terminal. This will allow you to compile and run Java files much like TextPad on PC.

Sources for the information and scripts provided in this article are courtesy of Gerry Jenkins, a professor at Long Beach City College, and George Benainous, a computer science teacher at Hollywood High. Although I have tested these scripts and they run on my Mac OS 10.7.5 system running TextWranger 4.0, I cannot guarantee that the scripts will run on your system, nor can I guarantee that it will run on earlier or later operating systems or versions of TextWrangler. If you are unfamiliar or uneasy with using the Terminal portion of your OS, please seek outside assistance or do some quick online research. If you have any questions about the scripts in this article, please contact Gerry Jenkins or George Benainous.

I cannot be held responsible for any faulty scripts provided in this article (as I am not the original author of them). This method is designed to give Mac Java beginners an alternative to TextPad. The following guideline will create two scripts that will allow you to compile and run Java files and programs using TextWrangler and the Mac Terminal.

Step 1

TextWrangler is a free text editor developed by Bare Bones Software. Download this software and install on your system.

Step 2

Once installed, open up TextWrangler. Navigate to the Scripting menu (the second menu to the left of Help menu). Select the “Open Script Editor” option.

Step 3

Next, you will copy and paste the following block of code into the Script Editor.

tell application "TextWrangler"
save text document 1
set the_file to file of text document 1
end tell

set AppleScript's text item delimiters to ":"
set source_file to the last text item of (the_file as string)

tell application "Finder"
set the_folder to container of file the_file
end tell

tell application "Terminal"
activate
set p to POSIX path of (the_folder as string)
set shell_script to "cd " & (quoted form of p) & ¬
"; javac " & source_file
if (count windows) is 0 then
do script shell_script
else
do script shell_script in the front window
end if
end tell

Step 4

In the Script Editor, go to File/Save As. Make sure that File Format is set to “Script”. Navigate to your MainDrive/Users/User/Library/Application Support/TextWrangler/Scripts directory. Save this file as Compile java.scpt.

Step 5

Once saved, go to File/Close. You will need to create another script, so go to File/New. Next, copy and paste the following block of code into the Script Editor.

tell application "TextWrangler"
set the_file to file of text document 1
end tell

set AppleScript's text item delimiters to ":"
set source_file to the last text item of (the_file as string)
set compiled_file to text 1 thru -6 of source_file

tell application "Finder"
set the_folder to container of file the_file
end tell

tell application "Terminal"
activate
set p to POSIX path of (the_folder as string)
set shell_script to "cd " & (quoted form of p) & ¬
"; java " & compiled_file
if (count windows) is 0 then
do script shell_script
else
do script shell_script in the front window
end if
end tell

Step 6

In the Script Editor, go to File/Save As. Make sure that File Format is set to “Script”. Navigate to your MainDrive/Users/User/Library/Application Support/TextWrangler/Scripts directory. Save this file as Run java.scpt .

Step 7

Once saved, you can quit the Script Editor. Now, restart TextWrangler. Navigate to the Scripting menu (the second menu to the left of Help menu). You should now see the 2 scripts we just created.

Step 8

Start writing a Java program. Running the Compile and Run scripts will open up the Terminal. If there are errors in your file, the Compile command will show you what lines the errors are occurring. If no errors are present, a .class file will be compiled in the same folder as the file currently open. When everything is good to go, run the “Run java” script to see the result of your program.

Related Goodness

  • inspirational CSS galleries
    150 Inspirational CSS Web Design Galleries
  • mobile optimization mistakes
    5 Mobile Optimization Mistakes That Hurt Your Website
  • compile Java files on Mac
    Compile And Run Java Files With TextWrangler On Mac
  • Google web font combinations
    Eye-Catching Google Web Fonts
  • fix Dell Dimension resolution
    Fix Dell Dimension 3000 Screen Resolution After Windows 7 Upgrade
  • increase followers on Twitter
    How To Increase Followers On Twitter
  • debt collection for web designers
    How Web Designers Can Collect Late Payments From Clients
  • import Excel sheet into phpMyAdmin
    Import Excel Data Into MySQL Using phpMyAdmin
  • Google Sheets Project Management
    Project Management Template For Google Sheets