posted on: 2016-01-27 10:22:19
This describes the very basics of a maven project. How to compile, run and make a library if necessary.

The first thing you should do is create a maven project with the standard directory structure, and a pom.xml. I used maven in 5 minutes to accomplish that. Once you know the structure though, it appears you can just create the files/folders manually.

I was attempting to get ClearVolume to build using this reference which had some trouble, but anyway. The important thing are the two external repositories that we have to add, and requiring the artifacts.

In this pom I add the repositories in the repositories section. And then the dependencies to the dependencies section, of course. This pom goes an step further and creates an uber jar of all the libs via the shade plugin. If I wanted to create an executable jar I include the following:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="" xmlns=""

If I wanted an executable jar then I would add the following to the execution tag.

    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

I based this pom information on the official reference. The jar is build by running,

mvn package

The was created when I generated the project, and I filled in the code.


import clearvolume.renderer.ClearVolumeRendererInterface;
import clearvolume.renderer.factory.ClearVolumeRendererFactory;
import clearvolume.transferf.TransferFunctions;
import coremem.types.NativeTypeEnum;

import java.nio.ByteBuffer;

 * Hello world!
public class App 
    public static void main( String[] args )

        System.out.println( "Hello World!" );
        // obtain the best renderer, this usually means picking the best supported GPU programming framwork such as CUDA or OpenCL or GLSL on the most performant GPU installed.
        final ClearVolumeRendererInterface lClearVolumeRenderer = ClearVolumeRendererFactory.newBestRenderer(
                "ClearVolumeTest",768,768, NativeTypeEnum.UnsignedShort,768,768,2, false

        // Different transfer functions can be used:

        // volume dimensions:
        final int lResolutionX = 256;
        final int lResolutionY = 256;
        final int lResolutionZ = 256;

        // size of the buffer in bytes (16bit data)
        final int lLengthInBytes = lResolutionX * lResolutionY* lResolutionZ* 2;

        // standard java byte array for holding the data:
        final byte[] lVolumeDataArray = new byte[lLengthInBytes];

        // Filling the buffer with some dummy yet interesting looking data:
        for (int z = 0; z < lResolutionZ; z++)
            for (int y = 0; y < lResolutionY; y++)
                for (int x = 0; x < lResolutionX; x++)
                    final int lIndex = 2 * (x + lResolutionX * y + lResolutionX * lResolutionY * z);
                    lVolumeDataArray[lIndex + 1] = (byte) (((byte) x ^ (byte) y ^ (byte) z));

        // sets the current buffer to be displayed:
                0, ByteBuffer.wrap(lVolumeDataArray), lResolutionX, lResolutionY, lResolutionZ

        // Waits for the renderer's window to be closed:
        while (lClearVolumeRenderer.isShowing())
            try {
            } catch (InterruptedException e) {

        // closes the renderer and release all resources:



Another way to run the program is to use:

mvn exec:java -Dexec.mainClass=""

Based on info found here.