Archive for April, 2006
Consistent library versions for maven2 dependencies
by on Apr.21, 2006, under Uncategorized
If you’re using maven2 for a multi module project, you want to make sure that each module uses the same version of libraries.
By specifying the <dependencymanagement> tag in your project pom, you can be sure of it.
<project>
...
<dependencymanagement>
<dependencies>
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring</artifactid>
<version>2.0-m3</version>
</dependency>
</dependencies>
</dependencymanagement>
...
</project>
In the module pom you define your dependency without <version></version>. Maven2 will take the version from the dependencyManagement section.
<project>
...
<dependencies>
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring</artifactid>
</dependency>
</dependencies>
...
</project>
external dependencies
by on Apr.13, 2006, under Uncategorized
There are a number of situations where you have to manually add packages to your local repository. All Sun packages for example are not available via the public maven repositories. A much more legitimate reason might be because you want to use a package which has not been official released yet. For example the pre release of easymocks classextension 2.0. Use the following lines to import those packages into your local maven2 repository. Of course you have to download the packages first.
mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=jta-1_0_1B-classes.zip
mvn install:install-file -DgroupId=easymock -DartifactId=easymockclassextension -Dversion=2.0 -Dpackaging=jar -Dfile=easymockclassextension2.0_Pre-Release.zip
mvn install:install-file -DgroupId=javax.sql -DartifactId=jdbc-stdext -Dversion=2.0 -Dpackaging=jar -Dfile=jdbc2_0-stdext.jar
a fresh book on maven2
by on Apr.10, 2006, under Uncategorized
One of the first books on maven2 has just been released. It is available for free download at Mergere.
1. Starting a project with maven 2
by on Apr.10, 2006, under Uncategorized
This is the start of a step-by-step tutorial into a number of libaries. The main idea is to document the experiences I have in getting to learn the development method at my new job. I’m going to build an application capable of ebusiness. I’ll start with the most basic functionality and slowly evolve into a full blown web application.
Part 1. Setting up a project
I’m going to start with Maven2. It’s a building tool similary to Ant. Most likely you can do exactly the same with Ant as with Maven2. So step 1 will be to setup Maven2.
Step 1 installing Maven2
- download Maven2 and store the content of the archive in some suitable place. I’ve placed it in development\tools
- Add an environment variable M2_HOME, pointing to the maven2 install dir.
- Add
%M2_HOME%\binto your path.
Now that we have Maven2 configured, we can start with our project.
Step 2 creating project
- run the following command on the place where you want to create your project directory, e.g. in development\projects.
mvn archetype:create -DgroupId=ebusiness -DartifactId=ebusinessThis will create a directory structure for you project and a maven configuration file, i.e. pom.xml
- Now that we have the maven default project set up, we want to adjust it to our needs. So let’s open the generated pom.xml and add some details to the project tag.
<name>eBusiness Web Application</name>
<description>This is the start of a step-by-step tutorial into a number of libaries. The main idea is to
document the experiences I have in getting to learn the development method at my new job. I'm going
to build an application capable of ebusiness. I'll start with the most basic functionality and slowly evolve
into a full blown web application</description>
<url>http://roald.bankras.net/ebusiness</url>
<developers>
<developer>
<id>Rowie</id>
<name>Roald Bankras</name>
<email>roald@bankras.net</email>
<roles>
<role>Project Manager</role>
<role>Architect</role>
<role>Developer</role>
</roles>
<organisation>JTeam</organisation>
<timezone>+1</timezone>
</developer>
</developers>
<build>
<plugins>
<!-- this is a java 1.5 project -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
- We need to tell maven that we want to create a war instead of a jar.
<project> ... <packaging>war</packaging> ... </project> - We can specify our web source directory by adding the following plugin to our pom.
<build> ... <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <warSourceDirectory>web</warSourceDirectory> </configuration> </plugin> </plugins> </build>
- Delete the ‘main’ and ‘test’ directories from your ’src’
- Create a directory ‘test’, for all your unittests, in your project root.
- In your project root also create a directory ‘web’ and a subdirectory ‘WEB-INF’. In the latter we will put our ‘web.xml’
mvn -Declipse.workspace=
eclipse:add-maven-repo
Next you can create your project files with mvn eclipse:eclipse. Now you can import this project into your workspace. For IntelliJ IDEA you can run mvn idea:idea in your project folder and open the project file in IntelliJ. Although the plugins for these IDEs are useful for linking to the required libraries, they are not without flaw. After opening the project into your favorite IDE, you’ll probably need to fine-tune the project settings. For example, in IntelliJ IDEA you need to enable java 5 capabilities.
Now that we have finished setting up our project, we can start building. Take a look in the next section.