Pular para o conteúdo
DocsTry Aspire
DocsTry

Get started with Java and Aspire

Este conteúdo não está disponível em sua língua ainda.

⭐ Community Toolkit Java logo

The Aspire Community Toolkit Java hosting integration adds Java executable and container applications to your AppHost. It supports Maven and Gradle wrapper workflows, running an existing JAR, and container images.

The integration is a hosting integration: install it in the AppHost, create a Java app resource, and apply a launch mode. An executable resource runs the local Java command, Maven wrapper, or Gradle wrapper from the configured project directory. A container resource runs an image. Both resource types can have endpoints, environment variables, health checks, and references configured through the AppHost.

Build helpers create setup resources that the executable application waits for during local development. JVM arguments and optional OpenTelemetry Java-agent configuration are supplied through JAVA_TOOL_OPTIONS.

  • Install a compatible JDK and ensure java is available on your PATH for executable resources.
  • Include the Maven or Gradle wrapper in your Java project and ensure its script is executable when you use those launch modes.
  • Install the Aspire CLI and meet the Aspire prerequisites.
  • Download the OpenTelemetry Java agent if you plan to configure an agent path.

Add CommunityToolkit.Aspire.Hosting.Java to the AppHost, then configure an executable Java application. This short example runs a Spring Boot application through its Maven wrapper:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddJavaApp("java-api", "../java-api")
.WithMavenGoal("spring-boot:run")
.WithHttpEndpoint(targetPort: 8080, env: "SERVER_PORT")
.WithHttpHealthCheck("/health");
builder.Build().Run();

Set up Java apps in the AppHost