Posts Tagged ‘Java’

Re-visiting Spring, Ivy and Maven – copy and paste configs

So its been a while since I did any Java development at home and having done enough at work I figured I would get a basic ivy setup with all the regular dependencies that I use for 90% of the projects I do at the firm and am likely to do at home so I can just copy and paste in the future. So feel free to… copy and paste!

I’m using Eclipse 3.5 with the IvyDE plugin. With those installed I created a new Java Project and then set about creating my ivy.xml. My projects pretty much all have the same basic dependencies

  • Spring (3.0.3.RELEASE since that’s the latest)
  • Hibernate (3.5.3.Final)
  • Hibernate-search (Makes indexing my model nice and easy)
  • Jodatime (Awesome for date manipulation)
  • Jodatime-hibernate
  • H2 database (I always start of with a mock in-memory at start of dev and then use some JPA magic to dump out a schema to DB2 or Sybase, or whatever else DB is in use)
  • SLF4J (My logging api of choice)
  • Jackson (For any restful services I might write)

Here’s my ivy.xml

< ?xml version="1.0" encoding="UTF-8"?>
< ?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?>
<ivy -module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://incubator.apache.org/ivy/schemas/ivy.xsd" version="1.3">

	<info organisation="mattgoldspink" module="gtdtd" revision="1.0.0" status="integration">
		<license name="Apache 2.0" url="http://www.apache.org/licenses/LICENSE-2.0"/>
	</info>

	<configurations>
		<conf name="compile" visibility="public" description="Maven compile dependencies"/>
		<conf name="runtime" visibility="public" extends="compile" description="Runtime dependencies"/>
		<conf name="test" visibility="private" description="Test dependencies"/>
	</configurations>

	<dependencies>
		<dependency org="org.springframework" name="org.springframework.spring-library" rev="3.0.3.RELEASE" conf="runtime->runtime" />
		</dependency><dependency org="org.hibernate" name="hibernate-core" rev="3.5.3-Final" conf="runtime->*" />
		</dependency><dependency org="com.h2database" name="h2" rev="1.2.137" conf="runtime->*" />
		</dependency><dependency org="org.hibernate" name="hibernate-validator" rev="4.0.2.GA" conf="runtime->*" >
			<exclude org="org.slf4j" name="slf4j-log4j12" />
		</dependency>
		<dependency org="org.hibernate" name="hibernate-entitymanager" rev="3.5.3-Final" conf="runtime->*" />
		</dependency><dependency org="org.hibernate" name="hibernate-search" rev="3.2.0.Final" conf="runtime->*">
			<exclude org="javax.jms" name="jms" />
		</dependency>
		<dependency org="joda-time" name="joda-time" rev="1.6" conf="runtime->*" />
		</dependency><dependency org="org.hibernate.javax.persistence" name="hibernate-jpa-2.0-api" rev="1.0.0.Final" conf="runtime->*" />
		</dependency><dependency org="joda-time" name="joda-time-hibernate" rev="1.2" conf="runtime->*">
			<exclude org="org.hibernate" name="hibernate" />
		</dependency>
		<dependency org="org.slf4j" name="slf4j-api" rev="1.5.6" conf="runtime" force="true"/>
		<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.5.6" conf="runtime" force="true"/>
		<dependency org="org.codehaus.jackson" name="jackson-core-lgpl" rev="1.5.3" conf="runtime" />
		<dependency org="org.codehaus.jackson" name="jackson-mapper-lgpl" rev="1.5.3" conf="runtime->*" />
	</dependency></dependencies>

</ivy>

I’m going to get my spring dependencies from Springsource’s ivy/maven repository, but everything else will come from a mix of JBoss and Maven2 repo’s. Here’s the ivy-settings.xml

< ?xml version="1.0" encoding="ISO-8859-1"?>
<ivysettings>

	<caches artifactPattern="[organisation]/[module]/[revision]/[artifact].[ext]" />
	<settings defaultResolver="ibiblio.jboss.java-net.springsource" checkUpToDate="true" />

	<resolvers>
		<chain name="ibiblio.jboss.java-net.springsource">
			<ibiblio name="ibiblio" m2compatible="true" />
			<ibiblio name="jboss" m2compatible="true"
				root="https://repository.jboss.org/nexus/content/groups/public-jboss" />
			<ibiblio name="java.net" m2compatible="true"
				root="https://repository.jboss.org/nexus/content/repositories/java.net-m2/" />
			<ibiblio name="java.net" m2compatible="true"
				root="http://repository.codehaus.org/" />
			<url name="com.springsource.repository.libraries.release">
				<ivy pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
				<artifact pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
			</url>

			<url name="com.springsource.repository.libraries.external">
				<ivy pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
				<artifact pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
			</url>
			<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>

	</resolvers>
</ivysettings>

After plugging the above into Eclipse and setting up my IvyDE classpath container to use the new ivy-settings.xml file there was one more thing to do which was to tell IvyDE what type the source jars were. Go to “Window” -> “Preferences”, find “Ivy” -> “Classpath” in the tree and on that page under the option for “Source types” enter “source,src,srcs”. Save and you should get source code attachment to the jars too. Note that you can tell your Eclipse project to use the ivy-settings within it by going right clicking on your Ivy classpath container and under “Ivy Settings Path” enter project:///ivy-settings.xml

Using Ivy with Springs repository and other Maven repositories

We use Apache Ivy in the office now and I thought I’d give it a proper whirl at home. In the office we have our repository to store all the libraries we have in our environment and so the setting up of resolvers etc is all taken care off. Out in the real world you need to do this yourself, but the beauty of Ivy is its simple. First up I’m using Eclipse 3.4 with the IvyDE plugin. With those installed I created a new Java Project and then set about creating my ivy.xml. For this project there are a few requirements I wanted.

  1. I want to use Spring for config
  2. I want to have a play with Compass – the lucene abstraction

Out of the box Ivy will use the “ibiblio” resolver which makes use of the Ibiblio’s Maven repository. This is not really the greatest starting point as its not so easy to find stuff in. Spring however have their own repository with a lot of open source libraries and is much easier to search http://www.springsource.com/repository/app/. So my ivy.xml file looks like:

< ?xml version="1.0" encoding="ISO-8859-1"?>
<ivy -module version="2.0">

	<info organisation="matt" module="compassTest" status="integration" />

	<dependencies>
		<dependency org="org.springframework" name="org.springframework.context.support"
			rev="2.5.6.A" />
		<dependency org="org.compass-project" name="compass" rev="2.2.0-M2" />
	</dependencies>

</ivy>

Very simply I want to use Springs context support classes and I want to have play with Compass. In order to get this all to work I needed to create my own ivy-settings.xml with some new resolvers. First I need to add Springs repository resolvers (Doc’d here), then I need to add Compass’s Maven repo and finally Compass depends on a version of Lucene not in Springs repository so I need to add in ibiblio’s Maven2 repository. My final ivy-settings.xml file looks like:

< ?xml version="1.0" encoding="ISO-8859-1"?>
<ivysettings>
	<settings defaultResolver="spring.compass.ibiblio" checkUpToDate="true" />
	<resolvers>
		<chain name="spring.compass.ibiblio">
			<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>
			<ibiblio name="compass" m2compatible="true" root="http://repo.compass-project.org" />
			<ibiblio name="ibiblio" m2compatible="true" />
		</chain>

	</resolvers>
</ivysettings>

After plugging the above into Eclipse and setting up my IvyDE classpath container to use the new ivy-settings.xml file all was good. Simples!

30Bots Update!

Thirty Bots LogoOK, so it’s been a while. I’ve been distracted and also, since Microsoft released Windows Live Messenger they’ve changed the whole handshake procedure which was a pain up the arse :( However, they did do something right & get some companies to release API’s written in a variety of languages to make creating a bots a hell of a lot easier. Further more, they’re encouraging people to write bots! With a $40,000 prize fund for the best! Luckily for me, my 30Bots handler is all done and dusted and needed hardly any work to port it over to one of these API’s! However, I still don’t have a permanent host for the bot, but my computer will do for now. If you bare with me while I tidy up the signing up procedure (found a small bug yday) I will release it’s address and you’ll be ready to use 30bots with your 30 boxes account!
UPDATE: It’s all up and running, except for adding new events (small problem with the Java API I’m using). So feel free to add the address thirtybots@hotmail.com to your contact list. If you find any bugs or want give feedback, do so within the IM window by typing either bug or feedback and then your comment.

Still To Do:

  • Reminders via the conversation window
  • Display and accept date according to users setting in 30boxes
  • Anything else that comes to mind or I recieve via feedback