CometD 2 Java Client Sample – open project in NetBeans based on Maven pom file, modify sources and run Java Based Comet Client

Lucas Jellema 1

On the heels of previous articles that described setting up NetBeans (, Tomcat 7 ( and the CometD 2 environment (, this article describes how I opened the Java Client Examples from the CometD project in NetBeans (creating a NetBeans project based on the Maven pom.xml included in the CometD distribution), made a few changes to the source and ran the sample from within NetBeans. Within minutes, the sample was running and ready for further manipulation.

The option to create a NetBeans project based on a pom.xml is very useful. The overall speed and responsiveness of NetBeans is also very pleasant.

The steps:

Start NetBeans.

From the File menu, pick the option Open project.



Navigate to the directory where CometD was installed. Browse to [C:\java\]cometd-2.3.1\cometd-java. Notice how NetBeans recognizes and interprets the pom files.


Select the cometd-java-examples directory/maven based project. Press Open project.

The project is now opened in NetBeans. All sources, configuration files and dependencies ready for inspection and manipulation.


To see one of the samples in action – the Java Chat Client that will communicate in a Comet style fashion with users of the Web Based Chat Client – open the source file in package org.cometd.examples.

Before we can meaningfully run the ConsoleChatClient, better first run Tomcat. Then check whether the chat demo is available – as well as the port number on which the Tomcat server is to be accessed:


Here we learn that the Tomcat server is listening on port 8085 (configured in the Tomcat server.xml file) and that the chat application is accessible through the cometSamplesFromWAR context path.

Now open the ConsoleChatClient. Locate the line where the defaultURL is set and use http://host:port/applicationContextPath/cometd as the default URL. In my case that means: “http://localhost:8085/cometSamplesFromWAR/cometd


Now we can run this class – through its main main method. The class will register a listener on the Chat channel. The initial messages seem a little unnerving, but it all turns out well:



In the browser user Nick will see the Java Client entering the chat:


After Nick types a welcome message, the console in NetBeans will read:


Now respond from the console in NetBeans:


And the response arrives promptly in the browser window:



With the sources set up in NetBeans, nothing will stop us from further investigating the options available in the CometD framework.

One thought on “CometD 2 Java Client Sample – open project in NetBeans based on Maven pom file, modify sources and run Java Based Comet Client

Comments are closed.

Next Post

Business Validation in Oracle SOA Suite 11g using Schematron

In a previous post I’ve explained the Schematron standard, how it works and how to use it. In the Oracle SOA Suite you can ‘Validate Semantic’ on the input (request) of a routing rule in a Mediator component by selecting a Schematron file. This is the Schemtron xml file in […]
%d bloggers like this: