Skip to main content
Blog

How to setup an isolated development environment

By 30 mei 2014januari 30th, 2017No Comments

With the prospect of a short but challenging assignment in a week, I had some time to configure my machine with a development environment. I wanted to have an isolated (VM) machine, but prefer working with my dev-tools on the native (non-VM) OS. Since I didn’t know what technology I would use (other than Java and PrimeFaces JSF) in my assignment, I sticked to the usuals: a Java web-application with PrimeFaces, MySQL, deployed on Tomcat, Eclipse for IDE and Maven for build, dependency and deployment. In this article, I would like to describe the issues and pitfalls I’ve encountered and how I solved them. So next time, you’re going to setup a development environment like this, you don’t have to fix these problems yourself. I already did that for you.

This is how I set it up:

VM setup

Dev-tools

Installing Eclipse and VirtualBox was easy. For Eclipse, I downloaded and unzipped the latest Mac OSX tar.gz, then moved that folder to the Applications. VirtualBox is just a dmg-file. I also installed the VirtualBox Extension-pack. I’m not sure why it was needed, I think it was needed to mount iso’s from your host to the guest’s virtual cd/dvd-drive. As for installing Maven, I used Homebrew. This package manager is the OSX equivalent of apt-get and allows you to easily manage and update lots of different tools, including Java, Grails and Ruby tools. Unfortunately it doesn’t support installing JDK, so that was done manually. The Oracle JDK download can be found here and is again, a pretty straightforward dmg-file.

Issues

Obviously, things didn’t all go according to plan. Some things were expected and easily fixed, while others were less obvious and required some more tinkering. Here’s a list of the things I’ve encountered.

Slow VM

While installing VirtualBox and setting up an Ubuntu VM was a breeze, actually running that VM was painfully slow. Even moving the mouse around, didn’t feel anywhere near what I would expect from the latest high-end hardware. Since the machine was virtual, there must be something wrong with resource-allocation to the VM. Google helped me to find the solution and in the end my virtual Ubuntu worked like a charm.

Apparently Ubuntu can’t use the graphics card for acceleration, Ubuntu uses CPU for rendering graphics trough LLVMpipe. That makes running ubuntu in VirtualBox really slow. To check if your Ubuntu guest is using 3D acceleration:

$ /usr/lib/nux/unity_support_test -p

You should see something like this:

Not software rendered: no
Not blacklisted: yes
GLX fbconfig: yes
GLX texture from pixmap: yes
GL npot or rect textures: yes
GL vertex program: yes
GL fragment program: yes
GL vertex buffer object: yes
GL framebuffer object: yes
GL version is 1.4+: yes
Unity 3D supported: no

If you see “Not software rendered” and “Unity 3D supported” both say no, this means Unity is using slow LLVMpipe. To enable 3D supported, first you will need to update linux-headers:

$ uname -r
$ sudo apt-get install linux-headers-$(uname -r)
$ sudo apt-get autoremove
$ sudo apt-get install build-essential

Download the latest VirtualBox Guest Additions iso here. The version I used was 4.3.8, which can be found here. Mount the image in VirtualBox in the host (while running) under VM -> Settings -> Storage -> Controller: IDE -> Attributes -> CD/DVD Drive. Then, you should have a disk mounted in Ubuntu, where you can install the VBoxLinuxAdditions:

$ cd /media
$ ls
$ cd username
$ ls
$ cd VBOX*
$ ls
$ sudo ./VBoxLinuxAdditions.run

Note: VirtualBox Guest Additions may not be activate on your Ubuntu. If so, go to System Settings, Additional Drivers to activate Oracle VM VirtualBox Guest Additions for Linux Module.

Next add vboxvideo to /etc/modules

$ sudo vim /etc/modules

Add “vboxvideo” at the end of the file:

loop
lp
vboxvideo

Reboot the machine. Then check “Not software rendered” and “Unity 3D supported” to see if your settings worked:

$ /usr/lib/nux/unity_support_test -p
...
Not software rendered: yes
...
Unity 3D supported: yes

The next thing you want to do is to increase video memory. Look for the .vbox file on your host machine:

$ vim /home/username/VirtualBox VMs/ubuntu/ubuntu.vbox

Upgrade the VRAMSize to 256 on this line:

<Display VRAMSize="256" monitorCount="1" accelerate3D="true" accelerate2DVideo="false"/>

Note, the ubuntu.vbox file is on the host-machine. The VM-settings in VirtualBox allow you to up the vram memory to 128, but you can simply go beyond 128 when editing the .vbox file manually.

Low VM resolution

At first, I wasn’t able to change the VM’s resolution. It was configured on a crappy VGA resolution, and I really like to have a GUI, just in case. Installing Ubuntu Virtualbox Guest Tools helped me to fix the resolution:

$ sudo apt-get install virtualbox-guest-utils virtualbox-guest-x11 virtualbox-guest-dkms

Host and Guest-VM unable to network

At first, I wasn’t able to reach the VM from the host and vice-versa. It took me a lot of Googling to have this fixed, so read along:

Host:

First up, lets configure the Host. Add a network under VirtualBox -> Preferences -> Network -> Host-only Networks:

Host-only-network

DHCP-server

Attach adapter2 to this network in the settings of the VM:

adapter2

Guest:

Next we’re going to configure the guest. Note: I tried to manually configure static-IP in /etc/network/interface but that horribly failed, after which I was unable to boot normally. So instead, open up the guest-OS System-settings and configure this under Network. Make sure you use the disconnected Wired connection, which should be set to 192.168.56.56

Adapter2-VM
Source for this solution: here

This enabled me to ping back and forth between 192.168.56.56 and 192.168.56.1.

Install Oracle Java on Ubuntu

Installing the Oracle JDK on Ubuntu is more complex as it is on Mac OSX. You can download the JDK tar.gz for your machine here. Please note, that you need to pick the correct version, based on your hardware-architecture (either i586 / 32-bit or x64 / 64-bit). In the following commands, we’ve used the x64 version for Linux.

Now copy the downloaded file to /usr/local/java:

$ cd ~/Downloads
$ sudo cp -r jdk-7u55-linux-x64.tar.gz /usr/local/java

Next, unpack it:

$ cd /usr/local/java
$ sudo tar xvzf jdk-7u55-linux-x64.tar.gz

Now we will add the location of java to the path. For this, we need to edit the profile:

$ sudo vim /etc/profile

Insert the following lines and correct the paths for your version

JAVA_HOME=/usr/local/java/jdk1.7.0_55
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
JRE_HOME=/usr/local/java/jdk1.7.0_55/jre
PATH=$PATH:$HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Now configure the location for java to be used when starting or compiling:

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_55/jre/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_55/bin/javac" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_55/bin/javaws" 1

And set these as the defaults to be used:

$ sudo update-alternatives --set java /usr/local/java/jdk1.7.0_55/jre/bin/java
$ sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_55/bin/javac
$ sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_55/bin/javaws

Finally, reboot and check the Java version used. It should log something like this:

$ java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

Install Tomcat and Manager apps

You have two options here:

I first tried to install Tomcat using apt-get, but I couldn’t find out how to install the manager-apps. I found out later, this can be done separately with sudo apt-get install tomcat7-docs tomcat7-admin tomcat7-examples . Instead I simply downloaded the tar.gz file and unzipped that to the ~/Documents folder. In the end, it’s a bit more convenient to have Tomcat and the webapps folder in your user directory.

However you install Tomcat, you still have to open up the admin-account in <apache-home>/conf/tomcat-users.xml. Add roles to the tomcat-users.xml file, so the admin-account has these access-rights:

<role rolename="manager"/>
<role rolename="admin"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="your-password" roles="admin,manager,manager-gui,manager-script,manager-jmx,manager-status"/>

After restarting Tomcat, you should be able to access the Tomcat manager from both guest-OS and host on this url: http://192.168.56.56:8080/manager.

Remote acces MySQL

The final thing to do, is open up MySQL for remote access. By default, MySQL only listens to 127.0.0.1, so we cannot access the database on the guest-OS from the host. This is done in two steps:

Add access rights to the root user from any IP on 192.168.56.%

On the guest-OS, start up the MySQL database and log in to MySQL with root:

$ mysql -uroot -p
Enter password:

Then grant access from 192.168.56.% to root:

GRANT ALL ON *.* to root@'192.168.56.%' IDENTIFIED BY 'root-password';

Open up MySQL to listen to the host

Open my.cnf and add or change the bind-address 192.168.56.56:

sudo vim /etc/mysql/my.cnf
# add or change this line:
bind-address = 192.168.56.56

Test everything

You may want to reboot the VM, to make sure everything is correctly initialized. Remember to manually start Tomcat if you used the tar.gz method and didn’t add it to init.d (see Automatic Starting in the guide mentioned previously).

Now, check the following stuff:

Tomcat Manager

On the host, browse to http://192.168.56.56:8080/manager and see if you can login with the credentials you’ve added to <apache-home>/conf/tomcat-users.xml.

MySQL

Start up a MySQL client (I’m using Sequel Pro) and try to login with root on 192.168.56.56. You can now add your application-specific database-scheme, users to access that databaase (make sure to grant access to those users on 192.168.56.%

Bonus: Automatic deployment

The final thing I wanted to do, is configure automatic deployment to Tomcat using Maven. For this, we need to supply Maven with the admin-credentials of our Tomcat server. These can be configured in your Maven %MAVEN_PATH%/conf/settings.xml:

<server>
<id>TomcatServer</id>
<username>admin</username>
<password>password</password>
</server>

Next, in your Maven project, configure the tomcat-maven-plugin:

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://192.168.56.56:8080/manager/text</url>
<server>TomcatServerUbuntuVM</server>
<path>/spring-primefaces-example</path>
</configuration>
</plugin>

This will allow you to do:

$ mvn tomcat7:redeploy -e
...
[INFO] Deploying war to http://192.168.56.56:8080/spring-primefaces-example
Uploading: http://192.168.56.56:8080/manager/text/deploy?path=%2Fspring-primefaces-example&update=true
Uploaded: http://192.168.56.56:8080/manager/text/deploy?path=%2Fspring-primefaces-example&update=true (18467 KB at 28675.0 KB/sec)
[INFO] tomcatManager status code:200, ReasonPhrase:OK
[INFO] OK - Deployed application at context path /spring-primefaces-example

Source for this solution: here

Conclusion

After some tinkering I have a stable deployment machine, virtualized on my local machine. I can start it up whenever I need to, but I don’t have the overhead of running services and databases when I don’t need it. On top of that, I can simply make a copy whenever I start a new assignment, as long as I keep a clean copy spare. And as long as my colleagues have a similar setup with VirtualBox, I can simply exchange VM’s so they can join development on the same projects in no time. This saves a lot of setup time.

[author] [author_image timthumb=’on’]https://first8.wpengine.com/wp-content/uploads/2014/05/2013-04-19.jpg[/author_image] [author_info]Bram started as a software developer in 2002, focusing on Java and web-applications. He prefers Linux (Ubuntu) and Mac OSX and uses lots of open-source tools, because of their platform in-dependency.[/author_info] [/author]