Using CAS with Maven 2 and Eclipse

Background 

Upon CAS 3.1.x, Maven 2 is used in project management, in which the infrastructure has changed a lot. New plugins are used in IDE integration also. Here is a brief introduction on integration with Eclipse using one of the plugins M2.

Who is this document targeting for?

The document is in specific written for deployers, who want to customize CAS for their own deployment environment. Those common customizations include:

  • adding own authentication handlers, either brand new or extending from the CAS project
  • adding own views and themes
  • changing parameters, values in configuration and properties files
  • (Something more?)

Assumptions

  • CAS 3.1.x or later
  • Eclipse 3.2 or later
  • Maven 2.0.x or later installed
  • Some knowledges on Maven 2 is good, but not necessary (I learnt Maven 2 at the same time as I used the plugin)
  • You need to customize CAS for the deployment in your environment

Walkthrough

As you may know, after using Maven 2 to manage the CAS project, it will be broken in Eclipse. Actually, M2 solves it by implementing the logic of Nested Modules. I will show below.

Before Eclipse,

  1. Install Maven 2.0.x to your machine
  2. Checkout cas project from the trunk, or perhaps one of the tags/branches
  3. Run "mvn package install" in the root folder where you checks out the project. Details go to Building and Deploying

Setting default environment in Eclipse,

  1. Install M2 plugin to your Eclipse, by the hints provided here.
  2. Create a new Java Project on the checked out project.
  3. Right-click the project -> Maven -> Enable Dependency Management
  4. Right-click the project -> Maven -> Enable Nested Modules
  5. The pom.xml file here thus should already include all the required libraries. That means this folder should not be broken by default. Result screen looks like this.
  6. You can also work only in webapp sub-project without using Nested Modules, this will also be much clear because usually we need not modify files in other cas sub-projects.

Customizing CAS,

  1. If you need to add dependency from other cas sub-projects, simply add the dependency tag to the pom.xml file under cas-server-webapp, like

     ...
    <dependency>
    	<groupId>org.jasig.cas</groupId>
    	<artifactId>cas-server-integration-jboss</artifactId>
    	<version>3.1</version>
    	<scope>runtime</scope>
    </dependency>
    ...
    

    The M2 plugin will automatically read the updated pom.xml file and include the necessary jars

  2. If you need to write your own handlers or other class files
    1. create the folder src/main/java under cas-server-webapp, add this to the source path
    2. write your classes within
  3. If you need to add views and themes, just put them in the appropriate folders in src/main/webapp
  4. If you want to modify the configuration and properties, most of them are located in src/main/webapp/WEB-INF/

Packaging CAS,
After all the customizations, it's time to pack things up for deployment. M2 has integrated to Eclipse for running the maven goals through External Tools.

  1. Right-click the project -> Run As -> Maven build
  2. Select the goal(s) you would like to run, for example "package" alone
  3. Run
  4. The progress is displayed in Console.
  5. (Optional) For some OS, JDK 5.0 cannot run several tests during normal build (Details here), you need to set -Dmaven.test.skip=true in console. In Eclipse, we will need to add a variable, with name "maven.test.skip" and value "true"

Problem

Even these are the steps for running maven in Eclipse, I do observe that running maven in Eclipse behaves differently as running in command line. In Eclipse, sometimes maven stops in the middle, or it shows errors even there should not be. So, for instant, I still suggest running in command line as the result is the one we need.

References

  1. http://maven.apache.org/eclipse-plugin.html
  2. http://m2eclipse.codehaus.org/
  3. http://www.eclipsetotale.com/tomcatPlugin.html
  4. http://harryworld.wordpress.com/2007/10/04/maven-2-make-the-application-management-better-and-easier/