Are you still deploying your Java application via SSH?
\n\nIf you've ever set up a Java project in production manually — mvn clean install, scp to the server, killing the process, restarting — you know that feeling: it seems to work, but every deployment feels like a boss fight. One forgotten flag, one wrong Java version — and the application crashes, and you get a "Server not responding" message at 3 AM.
Today we'll break down how to build a CI/CD pipeline for Java from scratch. It doesn't matter if you use Spring Boot, Micronaut, or good old Java EE — this pipeline will save your nerves and time. We'll use Jenkins, Maven, Docker, and GitHub. It will be real: with code, configs, and live examples.
\n\n\n\n
What is CI/CD and why does a Java developer need it?
\n\nCI/CD (Continuous Integration / Continuous Delivery) is not just a buzzword. It's a process that turns your code from "written on a whim" into "runs stably on the server" without your involvement.
\n\n- \n
- Continuous Integration — every commit is automatically built and tested. If tests fail, you find out instantly, not a week later. \n
- Continuous Delivery — after a successful build, the code is automatically deployed to a test or production server. \n
This is especially important for Java: building with Maven/Gradle, running unit tests, integration tests, code style checks — all of this can and should be automated. Otherwise, you'll spend hours on routine instead of writing features.
\n\n\n\n
Step 1. Environment setup: what we need
\n\nBefore writing the pipeline, let's make sure we have all the tools. For our CI/CD pipeline for Java, we'll need:
\n\n- \n
- GitHub (or GitLab/Bitbucket) — a code repository. \n
- Jenkins — an automation server. Can be run locally or on a VPS. \n
- Maven — a Java project builder. \n
- Docker — for containerizing the application. \n
- Server (or cloud) — where we will deploy. \n
Let's install Jenkins on Ubuntu (if you have a different OS, that's fine — the principle is the same):
\n\nsudo apt update\nsudo apt install openjdk-11-jdk\nwget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -\nsudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'\nsudo apt update\nsudo apt install jenkins\nsudo systemctl start jenkins\n\n\nAfter installation, open http://your-server:8080 and complete the initial setup. Don't forget to install plugins: Git, Maven Integration, Docker Pipeline, Blue Ocean (for a nice interface).
\n\n
Step 2. Writing a simple Java project (Spring Boot)
\n\nTo have something to practice on, let's create a minimal Spring Boot service. If you already have a project, just skip this step.
\n\n// Main.java\npackage com.example.demo;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@SpringBootApplication\n@RestController\npublic class DemoApplication {\n\n public static void main(String[] args) {\n SpringApplication.run(DemoApplication.class, args);\n }\n\n @GetMapping("/")\n public String hello() {\n return "Hello from CI/CD pipeline!";\n }\n}\n\n\nDon't forget the pom.xml with dependencies. A standard Spring Boot starter + Maven compiler plugin. This is our guinea pig.
\n\n
Step 3. Creating a Jenkinsfile — the heart of the pipeline
\n\nJenkinsfile is a declarative