Monday 10 August 2015

Building OpenJDK9 on the Cloud... Part 2

Continued from "Building OpenJDK9 on the Cloud...Part 1".
  • Connecting to your EC2 VM using PuTTY
  • Build Open JDK9
  • Store an Image of the EC2 VM


Connecting to your EC2 VM using PuTTY


The EC2 private key that you created previously isn’t supported by PuTTY.  The EC2 private key format is .pem, whereas the required PuTTy format is .ppk.  

First convert your EC2 private key to the PuTTY format using PuTTYgen.

Then using PuTTY, enter the session details.  Add the host name (i.e. ubuntu@xx.xx.xx.xx), Port 22, Connection type: SSH and save these.  

Then load the private key by going to Connnection/SSH/Auth.  Browse for the private key created using PuTTygen and click “Open”.
You should now have access to the VM on the AWS cloud.  Well done. :) 

Build Open JDK9



Install missing packages.

You will need all of the following installs.  


sudo apt-get install mercurial make build-essential zip unzip  libX11-dev libxext-dev libxrender-dev  libxtst-dev libxt-dev libfreetype6-dev libcups2-dev libasound2-dev  ccache  g++-4.7-multilib libffi-dev

I could not get this to work in one string, as detailed in the link above, so (annoyingly) had to run each in a new command.  The open jdk code is held in mercurial so add this too.

sudo apt-get install mercurial
sudo apt-get install make
sudo apt-get install build-essential
sudo apt-get install zip
sudo apt-get install unzip
sudo apt-get install libX11-dev
sudo apt-get install libxext-dev
sudo apt-get install libxrender-dev
sudo apt-get install libxtst-dev
sudo apt-get install libxt-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install libcups2-dev
sudo apt-get install libasound2-dev
sudo apt-get install ccache
sudo apt-get install g++-4.7-multilib
sudo apt-get install libffi-dev

Install Java 8. 
Java 9 is built from Java 8, so install Java 8 using instructions from the following link 
http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/ 
 
The instructions are 
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
Check the version 
$ java -version
  
Download and build JDK 9
$ hg clone http://hg.openjdk.java.net/jdk9/jdk9 jdk9
$ cd jdk9
$ chmod u+x get_source.sh
$ ./get_source.sh
$ bash configure --with-boot-jdk=/usr/lib/jvm/java-8-oracle --disable-warnings-as-errors
$ make clean images

Don’t fret if this doesn’t build in seconds.  The build took about 40 mins on a 1GB VM in Ireland, connecting from the UK. 

OK so you have connected to your shiny new VM, installed the software and built Java 9.  Hurrah! Give yourself a pat on the back.

Store an image of the VM

So that you don’t have to go through all this rigmarole again, it would be a good idea to store an image of the VM that you can use at a later date after you’ve closed and terminated the VM.  Click on “Actions/Image/Create Image”.  Give the image a name and save it.
                        



Your new AMI (Amazon Machine Image) will be viewable under the “Images” section of the EC2 Dashboard 




Now you can terminate your VM safe in the knowledge that an image has been saved for future use.

To create a new VM that uses a saved AMI
Mouse over the AMI, right click and select “Launch”.  This will bring you back to the “Select your Instance Type” page.  You could create a larger sized VM for a few pence per hour. I tried an 8 GB, 2 CPU Ubuntu m4.large.  When I loaded the AMI onto this machine I had a much faster response.

Remember to save an image of your new VM once you’ve completed your work.


And Finally.....

Do remember to terminate your VM – those few pennies can mount up if you forget about it!


That’s it.  Happy Hacking!

Sunday 9 August 2015

Building OpenJDK9 on the Cloud... Part 1


To build a VM in the cloud

  • Sign up to Amazon Web Services
  • Select EC2 from the AWS Dashboard
  • Launch a new instance
  • Create a new Key Pair
  • Connect to the VM


Sign Up to Amazon Web Services
Sign up for a free Amazon Web Services account http://aws.amazon.com/ 
Note: You will need to give your address details, bank details and your phone number in order to sign up – even if you already have an Amazon prime account.  Some of the EC2 instances are free but there is a cost associated with many instances although this cost is low.  Ensure you have your phone on you as you will receive a recorded message giving you a code to enter as part of the sign up.

Select EC2 from the AWS Dashboard
OK, so you’re in.  You should see something like this.
Click on “EC2 – Virtual server in the cloud”. http://aws.amazon.com/ec2/

You’ll be taken to the EC2 dashboard.  An example is below. This will show the resources you are using in the region you have selected.  You can change your region by clicking on the dropdown next to your name in the top right of the screen.




Launch a new Instance
Click on “Launch Instance” to create a new instance.  This will take you through the following steps:

Step 1: Choose an Amazon machine Image (AMI).  I chose Ubuntu.
Step 2: Choose an Instance type.  The Free instance is a titchy 1 GB with 1 CPU, but it is free!  (I used an Ubuntu t2.micro). Try this to start with or select a larger instance if you don’t mind spending the money.  The prices are low and are listed here: http://aws.amazon.com/ec2/pricing/
Clicking on “Launch” will accept the defaults and skip the next few steps to Step 7.
Step 3: Configure Instance details
Step 4: Add storage
Step 5: Tag Instance
Step 6: Configure security group
Step 7: Review Instance Launch

Before you can launch the new instance you will be asked to provide a Key Pair.

Create a new Key Pair
A key pair consists of a public key that AWS stores and a private key file that you store.  Together they allow you to connect to your instance securely. 

Create a new key pair, give it a name and download it.  Store it somewhere securely and remember the location as you will need this, particularly if you are intending to connect to your shiny new VM via PuTTY.

Launch your instance and click on “View Instance” to go back to the dashboard. Your instance may take a couple of minutes to launch.  The instance state will update once it is ready.





Once the VM is running, the instance state will change to “running”.


Connect to the VM
Click on “Connect”, this will bring up a pop up giving information on how to connect to your new VM


You have the option of connecting with a Java SSH Client or a standalone SSH client.  I couldn’t get the Java SSH Client to work so connected using PuTTY. (Continued in "Building OpenJDK9 on the Cloud... Part 2").

Saturday 8 August 2015

LJC Hackday - July 2015

I attended the London Java Community's Hackday on Sat July 18th which was very enjoyable and was well worth the trip down to London from Manchester. There I downloaded and built OpenJDK9 onto an AWS VM in the cloud.  


Useful Links:
Adopt open jdk getting started kit.

Getting started with Amazon EC2
https://aws.amazon.com/ec2/getting-started/

My notes of the day can be found in the following blog posts.  

Building openJDK9 on the cloud ... Part 1
Building openJDK9 on the cloud.. Part 2 

Should you, like I, not have enough space on your laptop to create a VM then I hope these posts will help you to learn something new and free up valuable time to play about with OpenJDK9.