Category

Run hsqldb from Eclipse

Introduction

You may be running HSQLDB from an ANT script or a batch file. You can create an Eclipse run configuration to start and stop the HSQLDB server from within Eclipse. As a bonus when you export your project ANT scripts there will be a target created to run the server from ANT.

Project Setup

Add the HSQLDB jar to your project’s classpath. Right click on your project and select properties from the context menu. Choose the Java Build Path item. If you are going to use HSQLDB in many projects it is worth the time to create a variable.
Press the Add Variable button to get the dialog and then press the Configure Variables button. Then press the New button to create a new variable. (You can get there through  Window->Preferences also.) Make up a descriptive name like HSQLDB 🙂 and then navigate to the location of hsqldb.jar on your filesystem.

Now create a (File->New->Folder) folder in your project. I named mine junkdb.

New Run configuration

Choose Run from the menu and then choose Run… to get the run configuration dialog. Choose Java Application on the left and then press the New button in the lower left. Give the configuration a meaningful name like “hsqldb server”. Choose your project you have set up. Specify org.hsqldb.Server as the main class. Check off “include libraries when searching for a main class”.

If you do not have hsqldb.jar in your project’s classpath you can specify it in your run configuration. Unfortunately you cannot use a classpath variable in your run configuration.

Run configuration 1

run1

Press the arguments tab.

For the program arguments enter

Uncheck “Use default working directory”. Press the Workspace button and navigate to the empty folder in your project you created previously.

Run configuration arguments

run2

Choose the Common tab. You may have to scroll to the right to see it. You can add this run configuration to your “favorites”. When you press the down arrow next to the run icon on the toolbar your favorites are at the top of the menu.

Run configuration options

run3

Go head and run the server now. The console will open and you will see the familiar output. To stop the server just press the red icon.

Console

hsqldb console

Refresh your workspace by pressing F5. Look at the contents of your database folder. It’s just internal HSQLDB junk but there they are! The files have the basename you specified in your arguments.

Database Directory

directory

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.