# JavaHostingExtensions

- Kind: `class`
- Package: [Aspire.Hosting.Java](/reference/api/csharp/aspire.hosting.java.md)
- Version: `13.6.0-preview.1.26478.8`
- Namespace: `Aspire.Hosting`
- Target framework: `net10.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting.Java/JavaHostingExtensions.cs)

Provides extension methods for adding Java applications to an `Hosting.IDistributedApplicationBuilder`.

## Definition

```csharp
namespace Aspire.Hosting;

public static class JavaHostingExtensions
{
    // ...
}
```

## Methods

- [AddJavaApp(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#addjavaapp-idistributedapplicationbuilder-string-string) : `IResourceBuilder<JavaAppResource>` `extension` `ats export` -- Adds a Java application to the application model, launched with `java`.
- [AddJavaApp(IDistributedApplicationBuilder, string, string, string, string[])](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#addjavaapp-idistributedapplicationbuilder-string-string-string-string) : `IResourceBuilder<JavaAppResource>` `extension` `ats export` -- Adds a Java application that runs a prebuilt JAR with `java -jar`.
- [AddJavaContainer(IDistributedApplicationBuilder, string, string, string?)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#addjavacontainer-idistributedapplicationbuilder-string-string-string) : `IResourceBuilder<JavaContainerResource>` `extension` `ats export` -- Adds a Java application that runs from an existing container image.
- [AddQuarkusApp(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#addquarkusapp-idistributedapplicationbuilder-string-string) : `IResourceBuilder<JavaAppResource>` `extension` `ats export` -- Adds a Quarkus application to the application model, built and launched with its own Maven or Gradle wrapper.
- [AddSpringBootApp(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#addspringbootapp-idistributedapplicationbuilder-string-string) : `IResourceBuilder<JavaAppResource>` `extension` `ats export` -- Adds a Spring Boot application to the application model, built and launched with its own Maven or Gradle wrapper.
- [WithGradleBuild(IResourceBuilder<T>, string[])](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withgradlebuild-iresourcebuilder-t-string) : `IResourceBuilder<T>` `extension` `ats export` -- Runs a Gradle build before the Java application starts.
- [WithGradleTask(IResourceBuilder<T>, string, string[])](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withgradletask-iresourcebuilder-t-string-string) : `IResourceBuilder<T>` `extension` `ats export` -- Launches the Java application through a Gradle task instead of `java`, for example `bootRun`.
- [WithJarArtifact(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withjarartifact-iresourcebuilder-t-string) : `IResourceBuilder<T>` `extension` `ats export` -- Selects the JAR the generated container image runs, for projects whose build produces more than one.
- [WithJvmArgs(IResourceBuilder<T>, string[])](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withjvmargs-iresourcebuilder-t-string) : `IResourceBuilder<T>` `extension` `ats export` -- Adds arguments to the Java Virtual Machine that runs the application.
- [WithMainClass(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withmainclass-iresourcebuilder-t-string) : `IResourceBuilder<T>` `extension` `ats export` -- Sets the main class an IDE launches when running or debugging this application. Has no effect on how Aspire starts the process, which is decided by the JAR path, Maven goal, or Gradle task.
- [WithMavenBuild(IResourceBuilder<T>, string[])](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withmavenbuild-iresourcebuilder-t-string) : `IResourceBuilder<T>` `extension` `ats export` -- Runs a Maven build before the Java application starts.
- [WithMavenGoal(IResourceBuilder<T>, string, string[])](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withmavengoal-iresourcebuilder-t-string-string) : `IResourceBuilder<T>` `extension` `ats export` -- Launches the Java application through a Maven goal instead of `java`, for example `spring-boot:run`.
- [WithOtelAgent(IResourceBuilder<T>)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withotelagent-iresourcebuilder-t) : `IResourceBuilder<T>` `extension` `ats export` -- Runs the application with the OpenTelemetry Java agent from the location the build tool writes it to.
- [WithOtelAgent(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withotelagent-iresourcebuilder-t-string) : `IResourceBuilder<T>` `extension` `ats export` -- Runs the application with the OpenTelemetry Java agent so it exports traces, metrics, and logs to Aspire.
- [WithWrapperPath(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting.java/javahostingextensions/methods.md#withwrapperpath-iresourcebuilder-t-string) : `IResourceBuilder<T>` `extension` `ats export` -- Overrides the build tool wrapper script path, for repositories whose wrapper is not in the default location or does not use the default name.
