Archive for category Reminders

Apache Ivy and Spring EBR

Here is how I set up the Apache Ivy dependency manager so that it can fetch springframework JARs from the SpringSource Enterprise Bundle Repository.

Listing: ivysettings-custom.xml

<ivysettings>
    <resolvers>
        <url name="com.springsource.repository.bundles.release">
            <ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            <artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
        </url>
        <url name="com.springsource.repository.bundles.external">
            <ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            <artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
        </url>
        <chain name="spring">
            <resolver ref="com.springsource.repository.bundles.release"/>
            <resolver ref="com.springsource.repository.bundles.external"/>
        </chain>
        <ibiblio name="jboss" root="http://repository.jboss.org/maven2/" m2compatible="true"/>
        <chain name="main" dual="true">
            <resolver ref="shared" />
            <resolver ref="public" />
            <resolver ref="spring" />
            <resolver ref="jboss" />
        </chain>
        <chain name="default" returnFirst="true">
            <resolver ref="local" />
            <resolver ref="main" />
        </chain>
    </resolvers>
</ivysettings>

Listing: ivysettings.xml

<ivysettings>
    <settings defaultResolver="default" />
    <include url="${ivy.default.settings.dir}/ivysettings-public.xml" />
    <include url="${ivy.default.settings.dir}/ivysettings-shared.xml" />
    <include url="${ivy.default.settings.dir}/ivysettings-local.xml" />
    <include file="ivysettings-custom.xml" />
</ivysettings>

This means that dependencies such as:

<dependency org="org.springframework" name="org.springframework.web.servlet" rev="3.0.2.RELEASE" />

should now be resolved correctly from the EBR.

Tags: , , , ,

Jsoup – BeautifulSoup for Java

HTML is notoriously difficult to parse and it has usually been a pain to do this in Java. Yes I know that there are parsers (like jtidy and nekohtml) that try to create a proper DOM but I’ve been waiting for something more lightweight.

Enter Jsoup. It feels like a mix of JQuery and Beautiful Soup (for Python).

String html = response.getContentAsString();
Document document = Jsoup.parse(html);

Elements elements = document.select("#errorRef");
assertThat(elements.size(), equalTo(1));

assertThat(elements.first().text(), equalTo(errorRef));

Mmm, full flavour, none of the fat.

Tags: , , , ,

PostgreSQL & Python on Mac

I’ve been playing with Django & MySQL for a while but for my next project I wanted to integrate it with a PostgreSQL database. Everything went well until I wanted to install Psycopg as my python adapter to PostgreSQL.

After a bit of blundering about here’s what it eventually took:

  • Download and install PostgreSQL one-click installer from http://www.postgresql.org/download/macosx. Remember to read the README file before actually running the installer.
  • Download the psycopg2 source from http://initd.org/pub/software/psycopg/.
  • Edit the setup.cfg file to provide a path to the pg_config executable. On my Mac it sits in /Library/PostgreSQL/8.4/bin/pg_config and is not by default on the PATH so if you don’t put it on the PATH or in this configuration file the next step will fail in a spectacular manner.
  • Run ‘sudo easy_install .‘ in the top level psycopg2 source directory.
  • Specify postgresql_psycopg2 when you configure Django’s database layer for your project.

Tags: , , ,