5.2. Managing VoltDB Development With Eclipse and Ant

It is possible to start a new VoltDB project from scratch within Eclipse. However, it is often easiest to import an existing project to ensure the build environment is set up correctly.

Ant is a software build automation tool designed specifically for Java applications that integrates well with Eclipse. If you use Ant as your automation tool, the easiest way to create a VoltDB project in Eclipse is to import an existing project, using your current Ant build file as the target of the import. If you do not have an existing project, you can create the preliminary project structure, including folders and stub files, using Ant to describe the structure. Then import the Ant build file into Eclipse.

5.2.1. Importing the Ant Build File into Eclipse

To import a project into Eclipse using Ant, do the following:

  1. Start Eclipse.

  2. Select New... Project... from the File menu.

  3. In the New Project dialog box, expand Java in the list of wizards and select Java Project from Existing Ant Buildfile and click Next.

  4. In the next dialog box, enter the build.xml from the directory where you created your template project as the Ant build file, and enter a descriptive project name. Then click Finish.

Eclipse creates a new project, leaving the source files where they are in your template project directory. You can now edit, build, and debug the source files from within Eclipse.

5.2.2. Managing Your Project in Eclipse

Once you import the project into Eclipse, you can manage, edit, and build your Java sources within Eclipse. Expanding the project name in the navigation window, you can double click on Java source files to open them in the editor. Selecting Build from the Project menu lets you compile the sources into class files.

Note that Eclipse doesn't know how to compile the VoltDB catalog directly. However, this task should still be a target within the Ant build file. To compile the catalog from within Eclipse:

  1. Expand the project in the Navigation window until you can see the build.xml file in the project contents list.

  2. Right-click on the build.xml file and select Run As... Ant Build... (item 2 from the popup menu).

  3. In the resulting dialog box, Make sure the Targets tab is selected and check the appropriate target within the build file for compiling both the stored procedures and the VoltDB application catalog.

  4. Switch to the Main tab and use the Browse File System... button to change the Base Directory to point to the root directory of your template project.

  5. Click Apply and then Run. (After applying your changes, you should not have to perform steps #3 and 4 again.)

Finally, there are two components of the VoltDB project that Eclipse does not recognize from the Ant build file. These are the project definition (XML) file and the database schema (SQL DDL) file. To manage the project properly, you should import these files as well so they are visible within the project package and you can edit them by double-clicking on them.

To import the files:

  1. Right click on the project name in the navigation window and select New... File.

  2. Make sure the correct project is selected in the selection box, then click on the Advanced >> button.

  3. Check the box for link to file in the file system, browse to your template project and select the file you want to import. Click Finish.

Once the files are imported, you can double-click on them in the navigation window to open them for editing.

Note

Eclipse can perform smart editing on XML and DDL files. However, Eclipse does not recognize .sql as a file type for database schemas and will start the default text editor to edit such files. If, before importing, you rename the schema to have the file type .ddl, Eclipse will recognize it and provide its own editor. However, you will need to edit the project.xml file as well to make the corresponding change to the project definition.

5.2.3. Running VoltDB Applications in Eclipse

Eclipse helps you compile your source files and the VoltDB catalog, as described in the preceding section. Once you have successfully built your application, you can run both the client and the server from within Eclipse as well.

  • To run the application server, right-click on the build.xml file, choose Run As... and specify the appropriate target for starting the server process. Eclipse will start the server and display any messages from the server process in the console window.

  • To run the application client, select Run... from the Run menu and specify your client application class as the Java application to run. Again, Eclipse displays messages from the client process in the console window.

There are limitations to running VoltDB applications in Eclipse. First, Eclipse can only run the client and server if the project is defined as a single server running on localhost. Also, the messages from one process (such as client) will replace those of the other (server) in the console window. However, running the application from within Eclipse can still be a very effective tool for testing and debugging the completed application locally before a full-scale build and test.