Monday, April 23, 2007

Extending Domino with Java - Part 2 - Simple Java

Now that we've downloaded eclipse, lets install the IDE and take a look. The eclipse install is easy - just unzip the folder to a directory of choice, it doesn't update the registry - simple and easy. I usually navigate to eclipse.exe and add a short cut to the desktop.

When I startup eclipse and I get the following error which means that I forgot to install the JSDK.

After I installed the JSDK eclipse starts up and stops to prompt you for the location of the workspace. I've chosen c:\workspaces\workspace so that I can keep them in one easy to backup location.



Next, close the Welcome screen and you then be in the Java perspective. Perspectives are the way that eclipse organises the files for different users and tasks. The default for the WTP is the Java perspective.

From the File > New > Other select the Java Project and enter an appropriate name and leave the default JRE selected.

The next Step is to get the HTTPClient code that we want to reuse. Using open source code can be hit and miss on the documentation front. Newer versions of projects do not have a great deal of documentation. However, the established project usually have more than enough examples, documentation and tutorials to get you started.

We'll download the HTTPClient 3.1 rc 1 version from the HTTPClient Project. We'll also need the other prerequsite projects, although we can skip the Junit project. Each zip file contains documentation and the *.jar files. These are the libraries that we want to reuse. I usually collect them into one single directory of jars that I want to reuse, in this example c:\lib.

Select the new project and in the properties > java build path select to add external jars. Navigate to the single directory and add each one.


So lets finish with a simple test - to confirm that we've got all the files that we need. There is a complete example in the HttpClient website. Select File > New > Class and enter the name of the class as HttpClientTutorial. The copy and paste the tutorial code. If everything is ok there should be no errors or warnings in the problems tab.


So lets execute the program. Select the java class file in the package explorer and then select run > run as > java application. This runs the class and starts with the main method. In the console tab you should see the html code for the apache.org website.


That's it a simple java program that gets the xhtml from a website using a http client. However, in this format is not easy for domino to consume. We will need to be able to pass parameters and decide how to handle errors, essentially hiding some of the complexity.

In the next post we'll build a facade to the HttpClient for use in Domino and add in authentication - ready for integration into a domino java agent.

1 comment:

  1. I found it makes a lot of sense to create a \lib directory in your Eclipse project, import your libraries there and reference them from there. While this will duplicate your jars when you have many projects, you avoid version conflicts and you make your project more shareable since everything is in one directory and also accessible when you use version control.
    Nice article!

    ReplyDelete