Example of using VBox plugin
Latest commit 692a31d Feb 23, 2013 @alexec Added travis.
Failed to load latest commit information.
src Added travis. Feb 23, 2013
.gitignore Added gitignore Jan 27, 2013
.travis.yml Added travis. Feb 23, 2013
MRPM-98.patch Added missing file. Jan 10, 2013
README.md Version 1.0.0 of the plugin. Jan 27, 2013
pom.xml Added travis. Feb 23, 2013



An example of using maven-vbox-plugin.

This app will:

  • Create a "Hello World" war.
  • Create a basic VM and install Tomcat6 on it.
  • Package the war in an RPM, with a dependency on Tomcat6.
  • Deploy that RPM to the VM.
  • Run an integration test.


  • Maven
  • Git
  • SVN
  • VirtualBox
  • rpmbuild (for the RPM plugin)

Firstly you need two get and compile two items. My plugin that creates VirtualBoxes:

git clone https://github.com/alexec/maven-vbox-plugin.git
cd maven-vbox-plugin
git checkout 1.0.0
mvn install

And the RPM plugin which we'll use to create the jar. There's a small bug in it which means if you're not creating an RPM on your target OS, yum might refuse to install it. We need to make a small patch, MRPM-98.patch:

svn co https://svn.codehaus.org/mojo/trunk/mojo/rpm-maven-plugin
cd rpm-maven-plugin
patch -p0 -i MRPM-98.patch
mvn install


Firstly we need to create the Maven project, we'll use a simple archetype:

mvn archetype:generate -DgroupId=com.alexecollins -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
cd hello-world

To the POM we need to add the plugin to create the VM:


We need to find a template VirtualMachine

mvn vbox:list-definitions

This will list the one we want, CentOS 6.3, to we'll get the added to our source:

mvn vbox:create-definition -Dvbox.name=CentOS_6_3

Now we have the box's definition in src/main/vbox/CentOS_6_3. Rename it to "app1" for now. I want to create a host only network so that it's easy to access and use the VMs, and it's good for SSH to and save setting up port forward we might want to share. Open VirtualBox.xml and replace the adapter with:

<Adapter slot="0">
     <HostOnlyInterface name="vboxnet0"/>
 <Adapter slot="1">

Keeping the NAT adapter allows the VM to speak to the Internet. It's quite feasible to create one VM (a gateway) that serve RPMs using FTP and provides SSH tunnelling.

Note that the name of the adapter differs between OSs, check in the preferences to find out (and to create one if needs be).

We need to update the Provision.xml to remove the port forward, delete this line:

<PortForward hostport="10022" guestport="22"/>

We also need to update the kick-start (ks.cfc) to enable the new adapter, we're going to give it an IP address in the same sub-net and the host-only network.

network --device eth0 --onboot yes --bootproto static --ip --noipv6
network --device eth1 --onboot yes --bootproto dhcp --noipv6

And we'll disable the firewall so our HTTP connection can get though (not very secure, but good for now):

firewall --disabled

We're going to deploy the webapp onto Tomcat 6. This Cent OS install is pretty basic. Modify the post-install.sh and add the following lines to install and start Tomcat before the power off:

yum -y install tomcat6
chkconfig tomcat6 on

We can test the setting easily, firstly create and provision the box:

mvn vbox:provision

It'll want to download the ISO, so you may want to go and get a cup of tea! Once that's complete, start the VM:

mvn vbox:start

Note: the default setting starts the VM in headless mode. You can switch to gui mode by changing Profile.xml:

<Profile xmlns="http://www.alexecollins.com/vbox/profile" type="gui">

See if you can hit Apache by opening:

You can stop the box:

mvn vbox:stop

A detail, but we need to let the plugin know when the box is ready to use (much like the Cargo plugin). Add this line to Profile.xml:

<ping url="socket://"/>

Next we need to build the war into an RPM:

        <group>Alex Collins</group>

If you're not familiar with RPMs, you might want to read up on this, but in summary it creates an RPM that copies the directory into Tomcat's webapp directory. Note the version is alpha-3, this includes the fix above. alpha-2 might serve your purpose if you host OS is Linux.

Finally, we need to deploy the RPM onto the box, we'll keep it simple and use Ant, so add this

                    <!-- note we force trust as new VMs will get new MAC etc. -->
                    <scp todir="root@" password="keenbrick" trust="true">
                        <fileset dir="${project.build.directory}/rpm/${project.artifactId}/RPMS/noarch"/>
                    <sshexec host="" username="root" password="keenbrick" trust="true"
                             command="yum -y install *.rpm"/>
        <!-- for SSH/SCP -->

We can test this by executing:

mvn pre-integration-test

vbox:start is bound to this phase, so it'll package the war, provision the vox, and deploy the war. Check out your handy work:

Next, an integration test, so enable add the fail-safe plugin to you POM and create an execution for the standard goals. Create a test named HelloWorldIT, with a single method:

public void testHelloWorld() throws Exception {
    assertTrue(Jsoup.connect("").get().html().contains("Hello World"));

You'll need to add JSoup and JUnit to the POM dependencies. Finally, test the whole thing:

mvn verify

Now, celebrate! OK, I've obviously not covered a number of topics, so here are some links to get you started.