惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
博客园_首页
罗磊的独立博客
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
Last Week in AI
Last Week in AI
D
DataBreaches.Net
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
D
Docker
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
H
Help Net Security
T
The Blog of Author Tim Ferriss

Nx Blog

Sharing Tailwind CSS Styles Across Apps in a Monorepo | Nx Blog How SiriusXM Stays Competitive by Iterating and Getting to Market Fast | Nx Blog Agentic Experience Is the New Developer Experience | Nx Blog Nx Joins the Linux Foundation and the Agentic AI Foundation | Nx Blog A Monorepo Is NOT a Monolith | Nx Blog Why we deleted (most of) our MCP tools | Nx Blog Teach Your AI Agent How to Work in a Monorepo | Nx Blog How Broadcom stays efficient and nimble with monorepos | Nx Blog Why Monorepos are King in the Age of AI | Nx Blog Nx 2026 Roadmap: Expanding Agent Autonomy, Improving Performance, Better Polyglot and More | Nx Blog End to End Autonomous AI Agent Workflows with Nx | Nx Blog Autonomous Agents at Scale | Nx Blog Scaling 700+ Projects: How Nx Became a 'No-Brainer' for Caseware | Nx Blog Configure Tailwind v4 with Angular in an Nx Monorepo | Nx Blog The Missing Multiplier for AI Agent Productivity | Nx Blog A Year of Nx Webinars | Nx Blog Wrapping Up 2025 | Nx Blog Nx 22.3 Release: Angular 21 Support, tsgo Compiler, and Prettier v3 | Nx Blog Nx Cloud Release: Agent Resource Usage | Nx Blog Nx Platform Outperforms DIY Cache by 5x | Nx Blog An Nx Carol: Past, Present, and Future of Your Monorepo | Nx Blog Nx 22.1 Release: Terminal UI on Windows, Storybook 10, Vitest 4, and more! | Nx Blog The Compounding Effect: How Nx Features Multiply Performance Gains | Nx Blog 10 Monorepo Myths Debunked: Separating Fact from Fiction | Nx Blog Nx Cloud Release: Enterprise Task Analytics | Nx Blog Watch and Rebuild Storybook Dependencies with Nx | Nx Blog Book - React for Enterprise: Timeless Architecture for Enterprise Apps | Nx Blog Beyond Remote Cache: Unlock 70% More CI Performance | Nx Blog Nx 22 Release: Expanding the build platform | Nx Blog What's the Point of Generating All This Code If You Can't Merge It? | Nx Blog
Seamless Java Deployment in Nx Using Docker | Nx Blog
Mike Hartington · 2025-08-01 · via Nx Blog

We've explored how you can add a Java app to an existing Nx workspace, but just getting the code in the same place doesn't really help ship our code. With JavaScript apps, you simply need to have a static hosting provider or have a platform that can run node. But Java? Where do you even begin? Let's look at how we can get our Java backend deployed and automate it using Nx. We'll also get a sneak peek at a new plugin we've been working on.

The Challenge: From Monorepo to Production

Running both the front-end and back-end within an Nx workspace is straightforward. But when it comes time to deploy your backend to a live URL, questions arise:

  • How do we package and deploy a Java application from the monorepo?
  • Do we need a hosting provider that supports Java by default?
  • How do we ensure consistent environments across different platforms?

The solution: Docker.

Docker allows us to encapsulate our backend into an image, ensuring that it will run consistently across AWS, GCP, or any other provider. By combining Docker with nx release, we can:

  • Automate the creation of Docker images for the backend.
  • Ensure builds are consistent and reproducible.
  • Push images directly to registries like Docker Hub for deployment.

The upcoming @nx/docker plugin takes this a step further, letting you define Docker workflows natively within Nx.

Setting Up a Dockerfile for the Backend

To get started, we create a Dockerfile inside the Java backend directory of the Nx workspace. This file tells Docker how to build and run our application:

FROM openjdk:26-slim-bullseye
MAINTAINER baeldung.com
EXPOSE 3000
COPY build/libs/java-backend-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
  1. Base Image: Use openjdk:26 as the starting point.
  2. Expose Ports: Our backend runs on port 3000, so we expose this port for the container.
  3. Copy the Build Artifact: Copy the generated .jar file into the container as app.jar.
  4. Set the Entry Point: Run the app with java -jar app.jar.

This simple setup ensures that the container will spin up our backend just like we would run it locally. Now, we can manually run Docker ourselves from the command line, but we have Nx here, and it can do that for us. Let's add the new Nx Docker plugin:

In my project, I need to setup some port forwarding, so that the port my Java app runs on, can be exposed when the Docker image is started.

{
  "name": "java-backend",
  "root": "apps/java-backend",
  "projectType": "application",
  "targets": {
    "docker:run": {
      "options": {
        "args": ["-p", "3000:3000"]
      }
    }
  }
}

With this, localhost:3000 will serve your API endpoints as if they were running directly on your machine.

Now with this new plugin, you can incorporate various Docker tasks in other parts of your Nx workflow, or as stand alone tasks. We can harness Nx’s task orchestration to build out a task pipeline. We can set docker:build to dependsOn: ["build"] and the @nx/docker plugin will already infer that docker:run dependsOn: ["docker:build"] ensuring that the docker image is available locally to run.

nx docker:run java-backend

All this from a simple command!

Integrating Docker with Nx Release

Now creating and running a docker image is fine, but we want to coordinate this as part of a release so everything we built can be shipped together. This is where nx release comes in. Let's add a new release configuration in our nx.json:

{
  "release": {
    "projects": ["java-backend"],
    "projectsRelationship": "independent",
    "releaseTagPattern": "release/{projectName}/{version}",
    "docker": {
      "skipVersionActions": true
    },
    "changelog": {
      "projectChangelogs": true
    }
  }
}

This is fairly standard release config, but the docker entry is new. The skipVersionActions tells Nx to not attempt to version any of the packages we’re releasing. Typically, this means bumping the version to the next major/minor/patch depending on your commits. Since this is just a demo, we don't really need worry about versioning any packages, just versioning the Docker image.

Then, we need to include some release configuration to tell nx release about where we want our java-backend released to. Let's open the project.json and add a new release setup:

{
  "name": "java-backend",
  "root": "apps/java-backend",
  "projectType": "application",
  "targets": {...},
  "release": {
    "docker": {
      "repositoryName": "nrwlmike/java-app"
    }
  }
}

The repositoryName is how nx release will know where it should upload the image to after it's ready. By default, this will publish to Docker Hub, but you can also set a registryURL to point it to your own private Docker registry if needed.

Now, it's time to ship it!

nx release --first-release

Nx will build, version, and publish your Docker image to Docker Hub.

Deploying Anywhere

With the Docker image published, deployment becomes as simple as pointing any provider—AWS, GCP, or others—to your image. Your backend will spin up in a consistent, production-ready environment.

The Docker plugin is still experimental, but its integration into Nx’s existing build and release workflows makes deploying backends seamless. It takes care of the tedious steps, allowing you to focus on building features rather than managing deployment scripts.

If you're interested in knowing more, let us know! Join our community Discord and be on the look out for the official release of the Docker plugin.


Learn more: