NetbeansedDerby

How to Work with Derby in the NetBeans IDE </div>

By: Daria Titova, with contributions of Mikhail Vaysman

August 2007

In this tutorial, you will convert Derby to a NetBeans project and know how to build and perform test runs of the Derby project in the NetBeans IDE. </span>

Contents


Introduction

Apache Derby is an open source relational database implemented entirely in Java. Derby is standards-based - Java, JDBC, and SQL, easy-to-use, and small - only 2 Mb. Derby also provides an embedded JDBC driver that lets you embed Derby in any Java-based solution.
You are also familiar with Derby if using Sun's JavaDB.
This tutorial shows you how to use the NetBeans IDE for Derby development.

The NetBeans Integrated Development Environment (IDE) is a free, open-source Integrated Development Environment for software developers. The NetBeans IDE provides developers with all the tools they need to create professional cross-platform desktop, enterprise, web, and mobile applications. In this tutorial, you learn how to convert a Derby project into a Netbeans project to develop, build, and test Derby within the Netbeans IDE.

For more information on how to work with the NetBeans IDE, see the Support and Docs page.

Software needed

Before you begin, you need to install the following software on your computer: NetBeans IDE 6.0, JDK 1.4, JUnit 3.8, Ant 1.6.2.
Since NetBeans 6.0 is under development now, use NetBeans IDE 6.0 Preview (M10) available from NetBeans IDE 6.0 Preview (M10) Download, or check the latest working version at http://bits.nbextras.org/netbeans/6.0/nightly/.
For its compilation Derby needs JDK 1.4, which is available from Download Java 2 Platform, Standard Edition, v 1.4.2; JUnit 3.8.2, which is available from Download JUnit; and Ant 1.6.2, which is available from Ant Archive.

Notations used in this documentation

  • <NETBEANS_HOME> - the NetBeans IDE installation directory
  • <USER_HOME> - the user's home directory. Example: "C:\Documents and Settings\user_home" for Windows OS.
  • <derby_src_root> - the directory with Derby sources
  • <jdk1.4> - the JDK 1.4 installation directory.
  • <ant1.6.2_home> - the Ant 1.6.2 home directory
  • <junit3.8.2> - the JUnit 3.8.2 file location


Exercises

Converting Derby to a Netbeans Project

To download the Derby sources:

1. Download the Derby latest official release from Apache Derby: Downloads. In this case it is 10.3.1.4 release.

2. Extract the archive file (in this case, the file name is db-derby-10.3.1.4-src.zip).
After the Derby archive file is extracted, you will see two subdirectories, in this case called db-derby-10.3.1.4-src and db-derby-10.3.1.4-doc-src. In this case, the db-derby-10.3.1.4-src directory is the <derby_src_root>.


To create the Derby NetBeans Project:

1. In the <USER_HOME> directory create ant.properties file, containing the following:

build.compiler=modern
j14lib=<jdk1.4>/jre/lib
proceed=true
sane=false
sanity=false
jdk=jdk1.4.2
derby.junit.classpath=./classes


2. Move <junit3.8.2> file to the <derby_src_root>/tools/java directory and rename it to junit.jar.


3. In the NetBeans IDE choose Tools > Options from the main menu. In the Options window click Miscelaneous button, change Ant Home location to <ant1.6.2_home> and add the following Ant properties:

ant.library.dir=<ant1.6.2_home>/lib/
java.home=<jdk1.4>/bin

Image:nb-ant-props_NetbeansedDerby.png

Note: Use '/' symbol when specifying Ant properties' path.


4. In the NetBeans IDE choose File > New Project from the main menu.
The New Project wizard opens.

5. In the Categories list, select "Java", in the Projects list, select "Java Project with existing ANT Script," and click Next.

6. At the Name and Location page, specify the locations of the Derby's project files and the build.xml file. In this case, the Derby project files are located at C:\tmp\db-derby-10.3.1.4-src\.
Type Derby in Project Name field to set the project's name.

Image:project-existing-ant_NetbeansedDerby.jpg

Click Next.

7. At the Build and Run Actions page, the IDE sets the following Ant targets in the fields listed below:

  • Build Project - build
  • Clean Project - clean
  • Generate Javadoc - javadoc
  • Run Project - derbyrunjar
  • Test Project - ckderbytesting

Change the value of some fields:

  • Build Project - buildsource
  • Run Project - empty
  • Test Project - testing junit-all

Image:project-actions-derby_NetbeansedDerby.jpg

Click Next.

Note: We've set Test Project Action as sequence of testing and junit-all tasks because testing task is for compiling Derby testing framework and junit-all is for running Derby junit tests.

8. At the Source Package Folders page of the wizard, specify all packages under the <derby_src_root>/java directory as source package folders.

Image:project-source-browse_NetbeansedDerby.jpg

Change Source Level to JDK1.4.

Image:project-source_NetbeansedDerby.jpg

Click Next.

9. At the Java Sources Classpath page, uncheck 'Separate Classpath for Each Source Package Folder' checkbox and add the following jars to the Java Sources Classpath list:

  • geronimo-spec-servlet-2.4-rc4.jar from the <derby_src_root>/tools/java directory
  • jakarta-oro-2.0.8.jar from the <derby_src_root>/tools/java directory
  • xercesImpl.jar from the <derby_src_root>/tools/java directory
  • xml-apis.jar from the <derby_src_root>/tools/java directory
  • junit-3.8.2.jar from the <derby_src_root>/tools/java directory
  • ant.jar from the <NETBEANS_HOME>/java1/ant/lib directory
  • tools.jar from the <jdk1.4>/lib directory
  • rt.jar from the <jdk1.4>/jre/lib directory

Image:project-classpath-src_NetbeansedDerby.jpg

Click Finish.

The Projects window contains the project node for the Derby project you have just created.

10. In the Projects window, right-click the Derby project node and choose Properties from the pop-up menu. In the Project Properties window, select Java Sources Classpath in the Categories list and change Java Platform to JDK 1.4.

Image:project-prop-classpath-jdk14_NetbeansedDerby.png

Click OK.

Note: If there is no JDK1.4 option in Java Platform field, click Manage Java Platforms button and add new Java Platform, pointing to the <jdk1.4> directory.


Now you can develop Derby within the NetBeans IDE.


Building the Derby Project

To compile the Derby project files, do the following:

1. In the Projects window, right-click the Derby project node and choose Build or Clean and Build from the pop-up menu.

Image:build-pr_NetbeansedDerby.jpg

The Derby source code is compiled and you see the "BUILD SUCCESSFUL" message in the Output window.

Image:building-derby_NetbeansedDerby.jpg


Testing the Derby Project

'Note': Be aware, the Derby tests run takes approximately 2 hours.

To perform testing of the Derby project, do the following:

1. In the Projects window, right-click the Derby project node and choose Test from the pop-up menu, or press Alt+F6.

Image:test-pr_NetbeansedDerby.png

A test run of the Derby project is performed and you see test results in the Output window.

Image:testing-derby_NetbeansedDerby.jpg


Summary

In this tutorial, you learned how to start Derby development in the NetBeans IDE. You have completed the following exercises:

  • Convert Derby into Netbeans Project.
  • Build Derby in NetBeans IDE.
  • Test Derby in NetBeans IDE.

See Also

References:

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo