Jenkins

JENKINS

What is..?

Jenkins is a tool (web application ) that helps in continuous integration of projects. It is open source and has capability to manage any types of build software. Jenkins can be seamlessly integrated with any testing and deployment environment.

Continuous Integration.

In software developement life cycle, there are various pahses of the software developement. In developement there may be checking in the code, modifying the code, testing, deployment , bug fixes etc. Continous Integration is a practise that requires developers to integrate code into a shared repository at regular intervals. The code can be checked in from various central repository such as GIT, SVN, CVS. They may be modified as per the requirements. Continious Integration is a practise that whenever a code commit occurs, the build process should be triggered.

How to get jenkins.

Jenkins can be downloaded from jenkins.io. Then it may be run from the command line using the java -jar command. It may be put in the application container such as tomcat, jboss, weblogics etc.

Once the Jenkins application is deployed in the machine, it has to be configured with the project repository, build tool (maven, ant etc) build time, testing configuration , email configuration etc.

After the above configuration is set , Jenkins create a disk-space to store all the projects, dependencies etc in a directory ~/.jenkins (default location). We may also change the location by setting the JENKINS_HOME environment variable before launching the servlet container.

 

Email Notification.

Jenkins also sends the email notification when any deployment event occurs. These email feeds can be managed in the email notification area. There is a provision to configure the SMTP settings for sending out emails.

 

Plugins

Jenkins ships in with many plugins to build project, manage project, add security, add user and organization level profile, etc We may also add plugins build for jenkins systems.

Manage Plugins screen helps to install, update and remove plugins.

Developing Custom Maven Plugins

Writing Custom Maven Plugins

In this article I would like to point you to a very handy concept i.e. writing custom maven plugins to facilitate in your build process.

If you are a Java developer then you must have been familiar with Maven. Basically maven is a build tool (but its developers say that it is more than that :)). It is a plugin execution engine that helps you write plugins, which can be executed in any maven life cycles.

Basically you will need to be aware of packaging modes, life cycles, build phases and goals of maven. If you are not aware of what all these are, you can find lots of online tutorials that give you good clarity.

Maven community has developed lots of plugins and for most of the use cases you may not need to write your own custom plugin. Sometimes your project build may have specific requiremts that does not get fulfilled by available plugins. In such case, if you have to write one – as I had to write – this tutorial helps you to get your hands dirty with some Java code to write plugins.

Just like POJO in java we have something known as MOJO – Maven plain Old Java Object.

What is a MOJO? (From apache documentation)

What is a Mojo? A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos.

In short, a mojo is a maven goal, to extend functionality not already found in maven.

So, if you have to write a plugin you are supposed to write one or more mojos.

Here is a sample Mojo(Create a separate maven project):

package com.helicaltech;

/**
 * @author Rajasekhar
 * 
 * Developed at Helical IT Solutions
 */
@Mojo(name = "repack",
        defaultPhase = LifecyclePhase.PACKAGE,
        requiresOnline = false, requiresProject = true,
        threadSafe = false)
public class SampleMojo extends AbstractMojo {
    //The parameter basedir is configured in the plugin configuration
    @Parameter(property = "basedir", required = true)
    protected File basedir;

    //Required = true means it is mandatory to configure the xml
    @Parameter(property = "warName", required = true)
    protected String warName;

    public void execute() throws MojoExecutionException {

        //Write your code here that will get executed
    }
}

Here, name attribut of Mojo is the name of the goal that you would like to run.

The @Mojo annotation defines that the name of the goal is “repack” and that it is not thread safe. It also defines the default phase is the package phase. The last thing is that any member variable can become a parameter. This becomes a parameter for the plugin of a goal.

Example usage of the plugin in POM:

                <plugin>
                <groupId>com.helicaltech</groupId>
                <artifactId>helical-maven-plugin</artifactId>
                <version>${helical.maven.plugin.version}</version>

                <configuration>
                <!--Parameter for the plugin go here -->
                    <basedir>${project.basedir}</basedir>
                    <warName>${project.build.finalName}</warName>
                </configuration>

                <dependencies>
                    <!--You can include the dependencies of your plugins here -->
                    <dependency>
                        <groupId>org.zeroturnaround</groupId>
                        <artifactId>zt-zip</artifactId>
                        <version>1.9</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                    <!--During the package phase the goal repack will be executed -->
                        <phase>package</phase>
                        <goals>
                            <goal>repack</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The groupId and the artifactId and the version numbers come from the POM file of your plugin.

Once you install the plugin to your maven local repository or your company’s shared central repository so that other developers can use your plugin.

Hope this article helped you and wish you happy coding!

–Rajasekhar
Helical IT Solutions

Installing Maven on Windows And Creating Maven project in Eclipse Juno

This blog talks about Installing Maven on Windows And Creating Maven project in Eclipse Juno

Maven is build and dependency management tool for java based application development, it is not install as windows service, rather is configured using windows environment variable.

In this post, I will summarize the steps need to install maven on windows operating system.

Step 1) Install java if not already installed

To install java download JDK installer from here and add/update JAVA_HOME variable

Go to control à system and security à system à advance system settings à advance tab à environment variables

Click on new under user variable give the variable name as JAVA_HOME and variable value path of JDK installation as shown below

Next go to system variable and select the path variable and click on edit button inset the JAVA_HOME variable created above go to end of the variable value and add ;%JAVA_HOME%\bin as shown below

Install Maven 2

Go to command line and check for class path whether is configured correctly or not.  Type the java – version as show below

Install Maven 3

It will show the version of java if class path is configured. If not shows the version repeat step 1.

 

Step 2) Maven Installation

Download Maven and extract it location where you want. Maven can be download from here.

I extracted in D:\Maven-3.2.1 you can choose your own.

Now, set MAVEN_HOME variable just you did as JAVA_HOME variable as show below

Install Maven 4

Install Maven 5

 

 

Step 3) Test for Installation

Maven installation is complete. Now lets test it for windows command prompt go to start menu and type cmd in application location search box press ENTER. Command prompt will be open and type mvn –version and hit ENTER. It will shows the version information of maven installed. If there is any error cross check the step 2.

Creating Maven Project in Eclipse

Step 1) Installing maven eclipse plug-in

Open the eclipse IDE go to Help à Eclipse Marketplace

Eclipse marketplace window will open and search tab is activated by default search for maven. All maven related plug-in will be display click and install the Maven Integration for Eclipse WTP (Juno). If it is already installed it will shows the Update as shown below.

Install Maven 6

Step 2) Creating Maven Project

To create dynamic web project with maven, navigate to the folder where you want to store the project and supply following command:

D:\Users\Java-Project\maven-project>mvn archetype:generate -DgroupId=com.helical.maven.sample -DartifactId=SampleMavenProject -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

 

What is groupId in maven ?

groupId identifies a particular project uniquely across all projects, so we should follow an naming convention. A very simple and commonly used way of doing this is to use reverse of your domain, i.e. com.helical.maven.sample

A good way of maintaining the integrity of groupId is to use the project structure. In case the project is consists of multiple modules than every module should append an identifier to the parent groupId. i.e. com.helical.maven.sample, com.helical.maven.spring, com.helical.maven.struts .. etc.

What is artifactId in maven ?

artifactId is the name of war file without version, if you are creating it by yourself you are free to took any name of your choice in lower case and without any strange symbol. But if this is a third party jar than we have to take the name of jar as suggested by it’s distribution.

What is archetype in maven ?

Archetype is a Maven project templating toolkit which tells the maven the type of project we are going to create. Archetype enables the maven to create a template project of user’s choice so that the user can get the project up and running instantly.

“archetype:generate”  generates a new project from provided archetype or update the actual project if using a partial archetype. Maven provides a number of predefined archtypes, see more details from Maven Documentation.

What is archetypeArtifactId in maven ?

While creating a new project we provide the archetypeArtifactId that informs maven about what archetype to use to create the initial structure of the project. Maven looks it up from the archetypeCatalog and works accordingly. e.g. If we want to create a simple web-app project we specify -DarchetypeArtifactId=maven-archetype-webapp.

 

Convert Maven project to support Eclipse IDE

Here we are done with creating a dynamic web project in maven, now lets make this project compatible to Eclipse IDE. To make maven project support eclipse ide navigate to project folder and supply following command :

D:\Users\Java-Project\maven-project \SampleMavenProjec>mvn eclipse:eclipse -Dwtpversion=2.0

Now import the maven project in eclipse as shown below.

Go to File import or right click import and select the Existing Maven Project click next

Install Maven 7

Browse to above created project directory and follows the steps and click on Finish.