Difficulty: Beginner
Estimated Time: 10 minutes

This tutorial shows you how to use Jenkins to orchestrate building a simple Java application with https://maven.apache.org/[Maven].

If you are a Java developer who uses Maven and who is new to CI/CD concepts, or you might be familiar with these concepts but don't know how to implement building your application using Jenkins, then this tutorial is for you.

The simple Java application (which you'll obtain from a sample repository on GitHub) outputs the string "Hello world!" and is accompanied by a couple of unit tests to check that the main application works as expected. The results of these tests are saved to a JUnit XML report.

You can stop this tutorial at any point in time and continue from where you left off.

If you've already run though link:..[another tutorial], you can skip the <> and <> sections below and proceed on to <>. (Just ensure you have link:https://git-scm.com/downloads[Git] installed locally.) If you need to restart Jenkins, simply follow the restart instructions in <> and then proceed on.

include::doc/tutorials/_prerequisites.adoc[] ** link:https://git-scm.com/downloads[Git] and optionally link:https://desktop.github.com/[GitHub Desktop].


[[fork-sample-repository]] === Fork and clone the sample repository on GitHub

Obtain the simple "Hello world!" Java application from GitHub, by forking the sample repository of the application's source code into your own GitHub account and then cloning this fork locally.

. Ensure you are signed in to your GitHub account. If you don't yet have a GitHub account, sign up for a free one on the https://github.com/[GitHub website]. . Fork the https://github.com/jenkins-docs/simple-java-maven-app[`simple-java-maven-app`] on GitHub into your local GitHub account. If you need help with this process, refer to the https://help.github.com/articles/fork-a-repo/[Fork A Repo] documentation on the GitHub website for more information. . Clone your forked simple-java-maven-app repository (on GitHub) locally to your machine. To begin this process, do either of the following (where <your-username> is the name of your user account on your operating system): If you have the GitHub Desktop app installed on your machine: .. In GitHub, click the green Clone or download button on your forked repository, then Open in Desktop. .. In GitHub Desktop, before clicking Clone on the Clone a Repository dialog box, ensure Local Path for: * macOS is /Users/<your-username>/Documents/GitHub/simple-java-maven-app Linux is /home/<your-username>/GitHub/simple-java-maven-app Windows is C:\Users\<your-username>\Documents\GitHub\simple-java-maven-app Otherwise: .. Open up a terminal/command line prompt and cd to the appropriate directory on: * macOS - /Users/<your-username>/Documents/GitHub/ Linux - /home/<your-username>/GitHub/ Windows - C:\Users\<your-username>\Documents\GitHub\ (although use a Git bash command line window as opposed to the usual Microsoft command prompt) .. Run the following command to continue/complete cloning your forked repo: + git clone https://github.com/YOUR-GITHUB-ACCOUNT-NAME/simple-java-maven-app + where YOUR-GITHUB-ACCOUNT-NAME is the name of your GitHub account.

Well done! You've just used Jenkins to build a simple Java application with Maven!

The "Build", "Test" and "Deliver" stages you created above are the basis for building more complex Java applications with Maven in Jenkins, as well as Java and Maven applications that integrate with other technology stacks.

Because Jenkins is extremely extensible, it can be modified and configured to handle practically any aspect of build orchestration and automation.

To learn more about what Jenkins can do, check out:

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Build a Java app with Maven

Step 1 of 5

Get started

Get your java source code

The first thing you start to play this tutorial is that get a git repository.

Please execute following command to get initial code from internal git server.

git clone https://[[HOST_SUBDOMAIN]]-3000-[[KATACODA_HOST]].environments.katacoda.com/butler/simple-java-maven-app

Run jenkins server

Render port 3000: https://[[HOST_SUBDOMAIN]]-3000-[[KATACODA_HOST]].environments.katacoda.com/ Render port 8080: https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/