Boulevard of Broken Builds

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>
Leave a Comment more...

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
Leave a Comment more...

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.

Leave a Comment more...

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%\bin to 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=ebusiness

    This 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>
    
  • I also want to seperator my sources and my test-source in the file structure and I want to use java 5 features, so I add the following section to
  • 
        <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>
    
  • As we are going to create a web application, we need specify it in our pom.
    1. We need to tell maven that we want to create a war instead of a jar.

      <project>
          ...
          <packaging>war</packaging>
          ...
      </project>
      
    2. 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>
      
  • Next, we have to clean up the generated file structure and create our own.
    • 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’
  • This is also a good point to start using your favorite IDE. For eclipse its a two step process. First you have to enhance your eclipse workspace with your maven local repository.
    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.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...