Build Java Project using Maven Jenkins Freestyle Job

In this article we are going to cover Build Java Project using Maven Jenkins Freestyle Job, Install GitHub Integration and Maven integration Plugins in Jenkins, Configure Source Code Management, Configure the Build steps, Configure Post-Build Actions, Monitor Build Progress.

What is Maven?

Apache Maven is a widely-used build automation and project management tool primarily used for Java projects, although it can be adapted for other languages and frameworks as well. It simplifies and automates the build process of software projects, making it easier to manage dependencies, compile code, package applications, and perform various other tasks related to software development.

What is build a Java project using Maven in a Jenkins Freestyle job?

Building a Java project using Maven in Jenkins with a Freestyle job involves configuring Jenkins to automate the build process of your Java application using Apache Maven.

Prerequisites:

  1. Jenkins Installed: Ensure Jenkins is installed and running.
  2. Maven Installed: Make sure Maven is installed on the machine where Jenkins is running.
  3. Java Project with Maven: Have a Java project configured with a pom.xml file that describes the project and its dependencies. A Java project with Maven hosted in a version control system like Git.

Build Java Project using Maven Jenkins Freestyle Job

Step #1:Log into Jenkins:

Open your web browser and navigate to your Jenkins instance.

login 1

Step #2:Install GitHub Integration and Maven integration Plugins in Jenkins

To build Java project with maven we need to install some plugins like,

  • GitHub Integration Plugin
  • Maven Integration Plugin

To install plugins follow below steps

Navigate to Dashboard->> Manage Jenkins ->> Manage Plugin

Now search for “GitHub Integration Plugin” and “Maven integration plugin” and click on checkbox after that click on  Download now and install after restart.

add plugins

Once the plugins are downloaded successfully. So now click on Restart Jenkins checkbox.

download progress

Please wait while Jenkins is restarting.

restart

Step #3:Create a New Freestyle Project in Jenkins

Click on “New Item” in the Jenkins dashboard.

new item

Enter a name for your project (e.g., “Java Maven Project”).

Select “Freestyle project” and click “OK”.

click on ok

Step #4:Configure Source Code Management for Build Java Project using Maven Jenkins Freestyle Job

In the job configuration page, scroll down to the “Source Code Management” section.

Select your version control system. For this example, we’ll use Git.

Enter the URL of your Git repository (e.g., https://github.com/yourusername/yourrepository.git). If your repository requires authentication, provide the credentials.

Specify the branch to build (e.g., “master” or another branch of your choice).

scm

Step #5:Configure the Build steps for Build Java Project using Maven Jenkins Freestyle Job

Add Build Step: In the “Build” section, click on “Add build step” and choose “Invoke top-level Maven targets.”

build steps 2

Configure Maven Build: In the “Goals” field, enter the Maven goals you want to execute (e.g., clean install). Specify the path to your pom.xml file. You can use the ${WORKSPACE} variable to refer to the Jenkins workspace where the code is checked out. For example: ${WORKSPACE}/path/to/pom.xml.

pom

Step #6:Configure Post-Build Actions for Build Java Project using Maven Jenkins Freestyle Job

Archive Artifacts: In the “Post-build Actions” section, click on “Add post-build action” and select “Archive the artifacts.”

post build action

In the “Files to archive” field, enter the relative path to the JAR or WAR file that Maven generates (e.g., target/*.jar or target/*.war).

jar

Step #7:Save and Build

  • Save the Configuration: Click on “Save” to save the job configuration.
  • Trigger the Build: After saving the job configuration, you can manually trigger the build by clicking “Build Now” on the job’s dashboard page.
build now

Step #8:Monitor Build Progress for Build Java Project using Maven Jenkins Freestyle Job

View Console Output: Click on the build number in the “Build History” section to view the console output. You can monitor the progress and identify any issues during the build process.

build history

Console output:

consol output

Check Artifacts: If the build is successful, you can go to the “Build Artifacts” section in the job page to download the archived artifacts.

build artifact 1

That’s the detailed process for configuring a Jenkins Freestyle job to build a Java project using Maven.

Conclusion:

In this article we have covered Build Java Project using Maven Jenkins Freestyle Job, Configure Source Code Management, Configure the Build steps, Configure Post-Build Actions, Monitor Build Progress.

Related Articles:

Build Java Project using Gradle Jenkins Freestyle Job

About Priti Adkine

I am Priti Adkine working as Software Engineer and having 1+ years of Experience. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link