Skip to content

Latest commit

 

History

History
99 lines (69 loc) · 3.27 KB

hosting-java.md

File metadata and controls

99 lines (69 loc) · 3.27 KB
title author description ms.date
Java/Spring hosting
justinyoo
A .NET Aspire hosting integration for hosting Java/Spring applications using either the Java runtime or a container.
10/11/2024

.NET Aspire Java/Spring hosting integration

[!INCLUDE includes-hosting]

[!INCLUDE banner]

In this article, you learn how to use the .NET Aspire Java/Spring hosting integration to host Java/Spring applications using either the Java runtime or a container.

Prerequisites

This integration requires the OpenTelemetry Agent for Java to be downloaded and placed in the agents directory in the root of the project. Depending on your preferred shell, use either of the following commands to download the agent:

# bash/zsh
mkdir -p ./agents
wget -P ./agents \
    https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
# PowerShell
New-item -type Directory -Path ./agents -Force
Invoke-WebRequest `
    -OutFile "./agents/opentelemetry-javaagent.jar" `
    -Uri "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar"

Get started

To get started with the .NET Aspire Azure Static Web Apps emulator integration, install the 📦 CommunityToolkit.Aspire.Hosting.Java NuGet package in the AppHost project.

dotnet add package CommunityToolkit.Aspire.Hosting.Java
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Java"
                  Version="*" />

For more information, see dotnet add package or Manage package dependencies in .NET applications.

Example Usage

The following sections detail various example usage scenarios, from hosting a containerized Spring app to hosting an executable Spring app.

In the _:::no-loc text="Program.cs":::_file of your app host project, call the AddSpringApp method to define the containerized Spring app. Use the JavaAppContainerResourceOptions to define the containerized Spring app.

var containerapp = builder.AddSpringApp(
    "containerapp",
    new JavaAppContainerResourceOptions
    {
        ContainerImageName = "<repository>/<image>",
        OtelAgentPath = "<agent-path>"
    });

In the :::no-loc text="Program.cs"::: file of your AppHost project, call the AddSpringApp method to define the executable Spring app. Use the JavaAppExecutableResourceOptions to define the executable Spring app.

var executableapp = builder.AddSpringApp(
    "executableapp",
    new JavaAppExecutableResourceOptions
    {
        ApplicationName = "target/app.jar",
        OtelAgentPath = "../../../agents"
    });

See also