Get started with Java and Aspire
Esta página aún no está disponible en tu idioma.
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.
How the integration works
Section titled “How the integration works”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.
Prerequisites
Section titled “Prerequisites”- Install a compatible JDK and ensure
javais available on yourPATHfor 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 a Java app
Section titled “Add a Java app”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:
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();import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const api = await builder .addJavaApp('java-api', '../java-api') .withMavenGoal('spring-boot:run', []) .withHttpEndpoint({ targetPort: 8080, env: 'SERVER_PORT' }) .withHttpHealthCheck({ path: '/health' });
await builder.build().run();Set up Java apps in the AppHost