News

Java Server Faces course available for RAD 6, WSAD and Eclipse.

Spring Framework Training available.

Hibernate Training available.

See resources for new J2EE articles

IDEs

Servers

Eclipse: Running HSQLDB

Gene De Lisa

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.

Toggle figure

Run configuration 1

run configuration

Press the arguments tab.

For the program arguments enter

-database.0 junkdatabase -dbname.0 junkdb

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

Toggle figure

Run configuration arguments

run configuration

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.

Toggle figure

Run configuration options

run configuration

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.

Toggle figure

Database Directory

console output

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.

Toggle figure

Database Directory


Rate this article Excellent   Good   Fair   Poor