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,
- Install Maven 2.0.x to your machine
- Checkout cas project from the trunk, or perhaps one of the tags/branches
- 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,
- Install M2 plugin to your Eclipse, by the hints provided here.
- Create a new Java Project on the checked out project.
- Right-click the project -> Maven -> Enable Dependency Management
- Right-click the project -> Maven -> Enable Nested Modules
- 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.
- 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,
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
- If you need to write your own handlers or other class files
- create the folder src/main/java under cas-server-webapp, add this to the source path
- write your classes within
- If you need to add views and themes, just put them in the appropriate folders in src/main/webapp
- 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.
- Right-click the project -> Run As -> Maven build
- Select the goal(s) you would like to run, for example "package" alone
- Run
- The progress is displayed in Console.
- (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.