Wednesday, April 9, 2008

Integrating JavaDB with Netbeans modules - Series 1

Here, I outline the series of steps to integrate JavaDB a.k.a Apache Derby with your Netbeans module. JavaDB acts as the embedded database for our Netbeans module. The network server features of JavaDB will not be utilized. I will also show how to configure the database so that it is stored in a custom location rather than the default.

Note: In trying out this guide, it is assumed that you are familiar with the Netbeans Platform and related concepts such as module, suite, etc. This guide is based on the latest Netbeans 6.1 Beta platform.
  1. Create a module suite with the name 'MyDbModule'. You can give any name you want. If you want to add JavaDB to an existing module suite project, skip this step.

  2. Right click on the project and select Properties. Select Libraries. In the Platform Modules section, uncheck all modules except platform8. We don't want other modules for now and if necessary, they can be added later.Click Ok when done.
  3. Add a new module to this suite. (If you already have a module, skip this step)
    1. Expand the suite tree node.
    2. Right click on Modules node and select Add New... You will see the following dialog:
    3. Type the name of the module as 'embedded-db'. Choose a location if required. Click Next. You will now see the following dialog:
    4. Type Code Name Base as 'org.embedded.db'. Keep the rest as default. You may change the module display name.
    5. Click Finish.
    6. Your new module is added to the suite 'MyDbModule'.
  4. Now add a dependency for JavaDB to this new/existing module. JavaDB is installed with Java SE 6. If you do not already have JavaDB, please install it first.
    1. Expand 'embedded-db' node.
    2. Right-click on Libraries and select 'Add New Library...'
    3. Browse for the JavaDB jar files. For a default installation in Linux, you will find it in /opt/sun/javadb/lib. For a default Windows installation, it will be in C:/Program Files/Sun/JavaDB/lib. Select derby.jar and then click Next.
    4. Give the project name as 'JavaDBLib'. Then click next.
    5. Set code name base as 'org.embedded.javadb'. Leave the rest as it is. Then click Finish. The library is added to the suite as well as a dependent library to 'embedded-db' project.
So far, we have created a new module suite, added a module and a JavaDB library wrapper to it. In the next part, we will dive into coding and see how to start up our database in our own location . Also, we will connect to the database using Java Persistence API and do some simple queries.

3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Bravo, this rather good idea is necessary just by the way

    ReplyDelete
  3. I am looking for such type of informative news and i get through this blog so i am very much thankful to you for sharing such a great information.
    - liferay portlet

    ReplyDelete