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"?>
<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

	<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"></license>

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


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"?>
	<caches artifactPattern="[organisation]/[module]/[revision]/[artifact].[ext]"></caches>
	<settings defaultResolver="ibiblio.jboss.java-net.springsource" checkUpToDate="true"></settings>
		<chain name="ibiblio.jboss.java-net.springsource">
			<ibiblio name="ibiblio" m2compatible="true"></ibiblio>
			<ibiblio name="jboss" m2compatible="true"
			<ibiblio name="java.net" m2compatible="true"
			<ibiblio name="java.net" m2compatible="true"
			<url name="com.springsource.repository.libraries.release">
				<ivy pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></ivy>
				<artifact pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></artifact>

			<url name="com.springsource.repository.libraries.external">
				<ivy pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></ivy>
				<artifact pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></artifact>
			<url name="com.springsource.repository.bundles.release">
				<ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></ivy>
				<artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></artifact>

			<url name="com.springsource.repository.bundles.external">
				<ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></ivy>
				<artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"></artifact>


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

Author: Matt Goldspink

I'm a web developer based in the UK. I'm currently UI Architect at Vlocity, Inc, developing UI's on the Salesforce platform using a mix of Web Components, Angular.js and Lightning.

3 Comments on “Re-visiting Spring, Ivy and Maven – copy and paste configs

  1. Your ivy.xml has typos, right?
    Why the close dependency tags?

    runtime” />


    Is the outermost tag “ivy” or “ivy-module” ?


    Can you explain a bit more about what you mean by “setting up my IvyDE classpath container to use the new ivy-settings.xml file ”


  2. Hi Alex,

    You’re correct. They are not intentional errors, it just seems the source code formatting plugin I use with wordpress screws it up everytime I save the post! I’ll see if I can find a better formatting plugin which doesn’t do this. In short the extra tags shouldn’t be there and the correct root element is <ivy -module>.

    > Can you explain a bit more about what you mean by “setting up my IvyDE classpath container to use the new ivy-settings.xml file ”

    By default IvyDE doesn’t know which ivy-settings.xml file to use, so it will use the default resolution mechanism (I think this is just the ibiblio resolver). We want it to use the custom one we’ve written which points to the jboss and springsource ivy repositories, so we need to tell it where this file lives. We can use the path “project:///ivy-settings.xml” to tell IvyDE to use the ivy-settings.xml in the root of the current eclipse project. That way you can always keep the ivy-settings.xml with your project code so anyone else who imports it will pick up the same resolvers and should be able to get the exact same dependencies as you. Note, it’s also worth checking in .project and .classpath files too if you change this so people can re-import the whole eclipse project and jump straight into coding without having to figure out who configured everything, but that’s a little off topic.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.