I can’t help but have to document this down, in case I forgot how to do it again. I am currently learning some basic computer programming using Groovy language. The reason I felt I have to write this down is because it is not as straight forward as clicking few buttons on the installation prompt. In fact, this has set me out to learn a lot of other things about computing.
I was given a set of instruction on how to install and use Groovy, however it wasn’t complete. So along the way, I have to figure out a lot of errors and fix it one by one. It is by no means an easy task as I have very minimal to zero background on this. Whilst internet searches help me to finally to figure this out, I couldn’t find a complete step-by-step instructions on how to install and laucnh Groovy, well, in a layman term. I guess that is probably due to most of the users have more knowledge about computing than me.
Yet I refused to give up as I found this so addictive that I couldn’t let go until I found the answer.
Here are the steps, in case I have forgotten.
a) Latest Groovy (as of now, the latest version is Groovy 2.1.6)
During installation of Groovy, do remember to change the directory of where the files are going to be stored. For some reasons, Groovy doesn’t work when there are space in the name of the file. Under normal circumstances, installation of new programme will be automatically stored in C:\Program Files or C:\Program Files (x86). Note there are space in between Program and File. This, based on my research on internet, is where Groovy may not work. So change the directory of where the files are going to be stored to C:\. Please refer to the following picture:
Another important step is to ensure that the path is linked to the command prompt file. During the installation process, the following box will be shown:
Do check the “Add to Path” box.
Then click next, and you will see 2 small boxes, the top one is checked and the bottom one is not. Don’t do anything here, except click “Next” or “Finish” (can’t recall now which one it is).
b) Java Platform (JDK) 7u25 (see note 1)
I downloaded Java SE Development Kit 7u25 (Windowsx 64 bit – as per my laptop).
(This is also where the note I was given didn’t specify which environment I should download. Painstakingly I finally found out different environments available and which environment I have to use.)
There are 3 different environments in Java. Simply put, if you just want to view and do not do any development, then just download JRE version (Java Runtime Environment). Java runs on a lot of platforms such as phone, TV, video, music, online games, etc.
JDK environment is basically for development purpose (Java Development Kit) and JRE is included in JDK too. That means by installing JDK, JRE will be automatically installed as well.
For Java, it is a normal installation process, just click some buttons to proceed each step. You’ll be prompt with whether you want to change the directory of the Java files will be located once it is installed. Check the box if you want to, otherwise just proceed.
2. After installation:
During the installation of Groovy, you may be prompt with the following information:
“Cannot identify Java installation. Assuming 32-bit”
I searched for answer, and the consistent answers are to do the following:
1. Go to Control Panel>System and Security>System>
2. Then select Advanced system settings and you’ll see the System Properties pop-up box tab Advanced, as follows:
Then click on “Environment Variables”and you should get a box, as shown on the left of the picture. This is where you are going to add the path (as in the location of where the files of Groovy and Java you have stored). Click “new” on the top (not below System variables) and you should see New User Variable prompt (right box on the picture:)
For Groovy, I found it only works if I input $GROOVY_HOME/bin to Variable Value instead of the directory of where it was installed. I am not too sure why.
Contrary to Groovy, I found that by inputting $JAVA_HOME/bin to the Variable Value doesn’t work, so I tried to input the directories of where Java was installed. To be precise, I actually had to try few directory paths, i.e. C:\Program Files\Java\jdk1.7.0_25\bin, C:\Program Files\Java and C:\Program Files\Java\jdk1.7.0_25, and only the last one worked. The other paths didn’t quite point exactly to the path where the JDK.exe file is located.
The following picture summarised the sequence and what it should look like once you have added all the paths:
Once you have done this step, restart the laptop/ computer as the paths will only be added/ take effect after restarting the system.
Now that installation is completed, the next hurdle for me was how to launch Groovy. This is where I learnt to use Command prompt for the first time. Anyway, once Command Prompt has been launched, follow these steps:
3. Type cd\ to change the directory and you can start to type the following:
Groovy Console will be launched.
4. It is advisable to write the programming script on a Notepad. To launch a Notepad, type
5. After the script has been written on Notepad, save it and make sure to add extension .groovy at the end of the file name in order for Groovy to identify the file. Close the file.
6. Back to Groovy Console that has been launched. Now open the notepad file, by performing the following task:
File>Open and select the location of where the file is stored and open.
7. Once notepad file is opened, the script should be shown on the top part of Groovy Console:
8. Click “Execute Groovy Script” as circled in red on the following picture:
Also note the that the bottom pane of the console is now repeating the instruction, and waiting for the input of a word.
This script is programmed for the user to key in input through command prompt. So launch the command prompt again and type in a word.
I have typed “I fell hyper!” and pressed Enter (this is important otherwise, Groovy doesn’t know you have finished typing). The output is then displayed on the bottom pane of the console:
See there’s another prompt to enter another word. It is waiting for the user to key in another input, and so I typed another word and press enter, as shown below:
Note at the bottom of the pane:
“Execution complete. Result was null.”
This marks the end of the script execution!