Categories
General

Adding Jetty 6 to Eclipse as a server runtime and overcoming the NullPointerException on Launch

I love Jetty. It is small, it is very fast and once you use it you start pondering why you use Tomcat. The reason in most cases is that you know Tomcat and it is relatively very well documented. Jetty is not as well documented but well worth the effort. One thing that Tomcat has and Jetty does not is built-in support in Eclipse as a server runtime.

The beauty of server runtimes is that you can easily deploy and update-on-the-fly web applications to the server. So if you modify a class in an web application, it is automatically updated – possibly restarting the server for you.

The makers of Jetty try to fill in this gap with their server runtime – which can be easily installed if you follow the instructions. Still, when trying to launch my web application on the new Jetty runtime, I kept getting an obnoxious, trace-free NullPointerException. As a user of Eclipse 3.3.2 Europa with little time to upgrade to Ganymede, I repeatedly tried to upgrade the WTP from my version 2.0.2 to whatever is current. That fails, in classic Eclipse fashion, because it is all geared at the *current* version of Eclipse (3.4).

What ended up working for me was to download the 2.0.2 patches from the WTP site. I extracted the files from the zip file to a directory. I then installed them using the update manager as a local site. To do that:

  1. Open the update manager: Help -> Software Updates -> Find and Install
  2. Choose ‘Search for new features to install’ and click ‘Next’
  3. Click ‘New Local Site’
  4. In the window that will open, point at the location that you extracted the zip file to, and in there, the ‘eclipse’ folder
  5. Click Finish

Eclipse will automatically install the patches, potentially restarting itself to have them take effect. This should cure the NullPointerException on launch for Jetty, and actually for several other servers that suffered from it in version 2.0.2 of the WTP in Eclipse 3.3.

NOTE:
If this does not work, also make sure that Eclipse is using the JDK’s JRE and NOT a generic Java JRE. A servlet container like Jetty must be able to compile files on the fly and therefore needs the JDK beyond the JRE.

Share
Categories
General

Smack API: Destorying persistent Multi-User Chat Rooms

Another one that is not documented.
Suppose you have a persistent Multi-User Chat Room (MUC) and room is empty. Apparently to destroy the room, the owner needs to join it, and then call the destroy() method on that room.
See, short and sweet.

Share
Categories
General

Smack API: No clean way to discover if a multi-user chat room exists

Here’s another one to follow the previous two posts about Smack API and Multi-User Chat issues.
Suppose you want to create a persistent room. Suppose you are not sure if that room already exists. In Smack, and I am not familiar of any other APIs, there is no non-exception-throwing way of doing this.

Fundamentally, a room already exists is the situation where a room is already set up on the server with the same name as the one you wish to create.

The MultiUserChat object has a static getRoomInfo() method which may have been the way to go. If the room does not exist, return null. Instead, if the room does not exist throws an XMPPException. Not sure what the error situation is here – I am just trying to find out if a room exists or not, but that causes an exception.

The flipside is on the creation end. If you try to create a room that already exists, an XMPPException will be thrown. This makes sense and is recoverable. Still, I am a fan of checking first instead of trying to do something only to encounter a bad situation. Not a biggie – just hope this spares someone the exploration and time. Not really documented, etc.

Share
Share