Software Development

SVN in Eclipse: Subversive and SVNKit for Subversion 1.6

Previously I had blogged about using JavaHL in Linux. JavaHL is the bindings to the native Subversion libraries which uses JNI, and it sometimes requires a bit of effort to get working. I no longer find using JavaHL necessary as I no longer have problems with the pure Java library SVNKit (formerly known as JavaSVN). I also have switched to Subversive instead of Subclipse because I have found it to be less problematic.

Despite being an official Eclipse project now, Subversive won't install from Eclipse 3.4's default repository, and you still need to get some plugins directly from Polarion. If you want to use the latest Subversive and SVNKit that supports Subversion 1.6, add the following update sites:

And then install the following from those update sites:

  • Subversive SVN Connectors (2.2.0)
  • Subversive SVN Team Provider (0.7.8)
  • SVNKit 1.3.0 Implementation (2.2.0)

Note that the version numbers will change in the future, but these are the current versions that work with 1.6.

URL Shortener Web Application Using Django

I created a URL shortener web application using Django (a Python web framework). I have made the source code available on GitHub and it is under an open source license (MIT license).

The shortened URLs use the base 62 value of ids of the model they are stored in, using the code from here (it uses A-Z, a-z, and 0-9), which should be fairly compact for a long time. A count of how many times the URLs are used is kept. The main page shows the 10 most recent and 10 most popular URLs.

You can see a running instance at n1l.us (which I am using to link to this blog and other links to my own content) and uu4.us (which I am using for all other URLs). I currently don't allow public submissions of URLs on either of those sites, but I will be opening it up for uu4.us at some point (perhaps once I add some defenses against spammers). The application itself has a configuration option to be able to require or not require login to be able to submit URLs (the REQUIRE_LOGIN setting in settings.py). Note that if you require logins, you have to use the admin app (at /admin/) as I have not created a separate login page.

I've so far done the bare minimum as far as HTML/JavaScript is concerned (and there is no CSS to speak of yet). Just enough to get things working. So don't expect a good looking site with this yet. It does produce a functional bookmarklet, assuming that you set SITE_NAME correctly for your site. Though I should probably make the bookmarklet check for rev=canonical to be a good web citizen.

The biggest issue with Adobe Flash Player

Update: Looks like they have fixed this in Flash Player 10.1

The biggest issue with Flash Player at the moment is that there is no way to create a top-level exception handler. What this means is that there will be exceptions (errors) that you simply cannot trap in your application code, even if you put try/catch all over your code (and especially if you are using Flex's MXML). This means that creating things like an error reporting tool are impossible for applications that run in the Flash Player (that includes AIR apps, too, not just browser apps). If you are running the debug version of the Flash Player, you will see uncaught exceptions, but the typical user is not going to be running the debug version. In the regular version of the Flash Player, uncaught exceptions just fail silently (often causing strange behavior), giving no indication to the user that an error occurred.

There is an issue in Adobe's issue tracker for this:

http://bugs.adobe.com/jira/browse/FP-444

It is the highest-voted issue specifically for the Flash Player. It is only surpassed by the request to keep developing Flash Builder for Linux, which I think is an important issue, but this issue is much more important. If you haven't already, create an account on Adobe's issue tracker and vote for this issue.

Suppress unchecked warnings on method calls in Java

Let's say you have a method call like this:

List<Object> list = (List<Object>) beanWrapper.getPropertyValue(key);

And beanWrapper.getPropertyValue returns an Object. If you have the "Unchecked generic type operation" compiler setting set to warning, you will get the following warning:

Type safety: Unchecked cast from Object to List<Object>

If you are using Eclipse, it will give you a quick fix to add a @SuppressWarnings(value = "unchecked") annotation, but only give you the option to add it to the current method.


(the current method in this case is getBean())

But we may not want to suppress warnings for the entire method. We can just put the annotation on the method call itself:

@SuppressWarnings(value = "unchecked")
List<Object> list = (List<Object>) beanWrapper.getPropertyValue(key);

CXF SOAP client built using Maven

I recently created some SOAP web service clients using Apache CXF (which is a project that resulted from the merging of XFire and Celtix). Rather than hunt down all the jar files I needed and write an Ant script to do the build, I decided to use Maven for this. It worked nicely and saved me some time (I can't say the same for some of the more complex projects I've tried to use Maven with).

I found the following blog entry very useful for setting this up:

How to create a WSDL-first SOAP client in Java with CXF and Maven

One thing I did different was use a property to specify the CXF version in one place:

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cxf.version>2.2.1</cxf.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>${cxf.version}</version>
    </dependency>

Pay attention to what it says about the cxf.xml file. I used the Maven Eclipse Plugin to generate my Eclipse project files. If you do this, but forget the cxf.xml file, your client may still work fine in Eclipse, but when you try to use the Maven-built jar file, you will get an error like this:

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
	at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:314)

Using Embedded Jetty with a Spring web application

Running a Java web application (that would normally run in a servlet container) using embedded Jetty is pretty useful because it means you can run it in a debugger with hot code replace without needing a special app server launcher.

To do this, I downloaded Jetty and included the jars as described in this document in my classpath:

http://docs.codehaus.org/display/JETTY/Embedding+Jetty

Then I followed the instructions here that Sanjiv Jivan had wrote up, making modifications that were specific for my environment:

http://jroller.com/sjivan/entry/embedding_jetty_in_a_spring

I have a class that looks like this:

import org.springframework.context.support.FileSystemXmlApplicationContext;
 
public class JettyLauncher {
    public static void main(String[] args) throws Exception {
    	new FileSystemXmlApplicationContext("path/to/jetty.xml");
    }
}

I launch that class inside of Eclipse in debug mode using a saved debug/run configuration that includes the Jetty jar files (but I don't have those jars in the main project classpath).

MyEclipse 7.0 Java template configuration bug

Update: This has been fixed in MyEclipse 7.1.

There is a bug in MyEclipse 7.0 which causes the template configuration preference to quit functioning. When I go into the template configuration, I get a dialog with the heading "Could Not Accept Changes" and the following error message:

The currently displayed page contains invalid values.

And the configuration page is almost completely blank. It just says "Create, edit or remove templates:".

This has been reported at this forum topic and they are aware of the bug. It exists in 7.0 M2 and 7.0 GA. MyEclipse 6.5 (w/ Eclipse 3.3) doesn't have this problem.

Workaround

I use this rather inconvenient workaround to get around this:

My workaround is to use a clean copy of Eclipse (that doesn't have MyEclipse installed) with its own workspace, and edit my custom templates in that copy. Eclipse stores custom templates in this file (along with a lot of other configuration):

ECLIPSE_WORKSPACE/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs

So what I do is I copy the line that starts with "org.eclipse.jdt.ui.text.custom_templates=" followed by XML from the clean copy to the one with MyEclipse installed. And restart Eclipse to pick up the change.

If you try this workaround make sure to make a backup of this file before you edit it, just in case something goes wrong.

Using relative paths for Django template directories

Django's template dirs are specified as absolute paths in settings.py:

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

But since this is just Python code, it is relatively easy to specify relative paths (no pun intended). As described in this blog, add the following code to settings.py:

import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

And then in the TEMPLATE_DIRS section you can specify a relative path like this:

TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates')
)

A useful introduction to JavaScript video lecture

I came across the following video ("The JavaScript Programming Language") that is a lecture by Douglas Crockford (who is a "JavaScript Architect" at Yahoo!) in which he discusses JavaScript. It is split into four 30-minute parts (totaling 2 hours):

It's useful to download the slides because the video doesn't always show them when he is referring to them.

It is a good introduction to JavaScript, explaining how parts of the language works as well as offering advice on how to use (or not use) various features of it. He also talks some about the history of the language.

Getting Postgresql running on Ubuntu and OS X (Leopard)

Here are some good articles on how to get going with Postgresql on Ubuntu:

http://help.ubuntu.com/community/PostgreSQL

And Mac OS X 10.5 (Leopard):

http://www.z1r0.com/2008/03/configuring_postgresql_82_in_o.html

Note that version numbers don't matter, as I was able to apply these instructions to Postgres 8.3.

I also find the pgadmin3 tool to be very helpful with Postgres. In Ubuntu you can find it in the repositories, in Mac OS X, you can get a binary to install from here.

Syndicate content