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.
To import a project into Eclipse using Ant, do the following:
Select New... Project... from the File menu.
In the New Project dialog box, expand Java in the list of wizards and select Java Project from Existing Ant Buildfile and click Next.
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
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.
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:
Expand the project in the Navigation window until you can see the
build.xml file in the
project contents list.
Right-click on the
build.xml file and select Run As... Ant
Build... (item 2 from the popup menu).
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.
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.
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:
Right click on the project name in the navigation window and select New... File.
Make sure the correct project is selected in the selection box, then click on the Advanced >> button.
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.
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.
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.