6.6. Compiling and Running Client Applications

Documentation

VoltDB Home » Documentation » Using VoltDB

6.6. Compiling and Running Client Applications

VoltDB client applications written in Java compile and run like other Java applications. (See Chapter 8, Using VoltDB with Other Programming Languages for more on writing client applications using other languages.) To compile, you must include the VoltDB libraries in the classpath so Java can resolve references to the VoltDB classes and methods. It is possible to do this manually by defining the environment variable CLASSPATH or by using the -classpath argument on the command line. If your client application depends on other libraries, they need to be included in the classpath as well. You can also specify where to create the resulting class files using the -d flag to specify an output directory, as in the following example:

$ javac -classpath "./:/opt/voltdb/voltdb/*" \
        -d ./obj  \
         *.java

The preceding example assumes that the VoltDB software has been installed in the folder /opt/voltdb. If you installed VoltDB in a different directory, you need to include your installation path in the -classpath argument.

If you are using Apache Maven to manage your application development, the VoltDB Java client library is available from the central Maven repository. So rather than installing VoltDB locally, you can simply include it as a dependency in your Maven project object model, or pom.xml, like so:

<dependency>
    <groupId>org.voltdb</groupId>
    <artifactId>voltdbclient</artifactId>
    <version>5.1</version>
</dependency>

6.6.1. Starting the Client Application

Before you start your client application, the VoltDB database must be running. When you start your client application, you must ensure that the VoltDB library JAR file is in the classpath. For example:

$ java -classpath "./:/opt/voltdb/voltdb/*"  MyClientApp

6.6.2. Running Clients from Outside the Cluster

If you are running the database on a cluster and the client applications on separate machines, you do not need to include all of the VoltDB software with your client application. The VoltDB distribution comes with two separate libraries: voltdb-n.n.nn.jar and voltdbclient-n.n.nn.jar (where n.n.nn is the VoltDB version number). The first file is a complete library that is required for building and running a VoltDB database server.

The second file, voltdbclient-n.n.nn.jar, is a smaller library containing only those components needed to run a client application. If you are distributing your client applications, you only need to distribute the client classes and the VoltDB client library. You do not need to install all of the VoltDB software distribution on the client nodes.