Today I'd like to show you how you can run your first CORBA application in NetBeans 6.0 without any additional IDE-Plugins but don't expect a CORBA tutorial because this would be an issue for more than one blog post. Besides you will find a really good and detailed documentation in your JACORB_HOME\doc directory. First of all I'd like to provide the links where you can find all necessary resources for this tutorial.
Resources:
Requirements:
- Java SDK ;-)
- Installed NetBeans IDE
- Added JACORB_HOME to your system-properties
I will use a demo application (grid) which you will find in the JACORB_HOME\demo directory. Because I only want to show you how to bring your CORBA installation up and running I won't implement an application from scratch. After you have prepared all configurations it would be very easy for you to implement a new Java application. So let's start by creating a new Java-Project in your NetBeans IDE. I simply called it 'Grid'. Now you have to add all the necessary JacORB-libraries which you will find under JACORB_HOME\lib into your IDE and add it to your project's classpath.
Necessary Libraries:
- avalon-framework-4.1.5.jar
- jacorb.jar
- idl.jar
- logkit-1.2.jar
The next step is to create the necessary java-packages ('demo.grid') for the demo-application and then simply copy the demo-app's sources to the demo.grid package.
Files to copy:
- Client.java
- Server.java
- TieServer.java
- gridImpl.java
- gridOperationsImpl.java
- server.idl
After you've copied all the necessary files, create a new folder in your project, I called it 'cust'. Download and save the following file into this new folder. This file is a custom ant-build.xml file for your application. It provides targets e.g. to start the namespaces-server, to invoke the idl-compiler pointing to your server.idl which will generate all necessary stub-classes for the corba-application.
Build.xml
I've changed the module structure in the sever.idl file by adding a new module (which will be a generated java-package) called 'gen'. That's because I'd like to have the generated artefacts in a separated package.
server.idl:
module gen {
module demo
{
module grid
{
interface MyServer
{
typedef fixed <5,2> fixedT;
readonly attribute short height; // height of the grid
readonly attribute short width; // width of the grid
// set the element [n,m] of the grid, to value:
void set(in short n, in short m, in fixedT value);
// return element [n,m] of the grid:
fixedT get(in short n, in short m);
exception MyException { string why; };
short opWithException() raises( MyException );
};
};
};};
The following picture shows how your folder-structure should now look like.
Now, open your custom build.xml and run the 'idl-compile' target in the navigator-view of your IDE. This will compile your server.idl and generate all necessary stub-classes to run your application. Your application should still have some errors. That's because we've changed the server.idl and hence the java-package structure and all the dependencies of your java-files can't be resolved because they aren't pointing to gen.demo.grid. You will be able to solve those errors by open up each java-file and press Ctrl+Shift+I to fix all imports.
You now should still have some errors. That's because some packages have been hardcoded in the demo-application. Just rename those packages from demo.grid to gen.demo.grid. Then there should be no errors anymore and you will be able to run the application and those are the steps to complete this tutorial:
- run compile target
- run run-ns target
- run run-grid-server target
- run run-grid-client target
Then you should see something like the following screen shows:
From here this is a good starting point to go through the JacORB's documentation and study all the demo app's sources. Then you will have a pretty good understanding on how CORBA works. Of course CORBA is a pretty complex technology but there are many more demo applications which you will find under the JACORB_HOME\demo directory. So enjoy coding CORBA apps with NetBeans IDE.
Cheers