# JavaAppResource

- Module: [Aspire.Hosting.Java](/reference/api/go/aspire.hosting.java.md)
- Version: `17.0.0-preview.1.26565.2`
- Kind: `handle`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/bcfa151cdca6d0a573f22d5d9c23f9c727cb3b2f)

Represents a Java application resource in the distributed application model.

## Remarks

The command is always `java`. When the application is launched through a Maven goal or a Gradle
task, the wrapper script replaces that command; see `WithMavenGoal` and `WithGradleTask`.

## Definition

```go
type JavaAppResource interface {
    IComputeResource
    IContainerFilesDestinationResource
    IJavaAppResource
    Resource
    ResourceWithArgs
    ResourceWithEndpoints
    ResourceWithEnvironment
    ResourceWithWaitSupport
}
```

## Embeds

- `IComputeResource`
- `IContainerFilesDestinationResource`
- [`IJavaAppResource`](/reference/api/go/aspire.hosting.java/ijavaappresource.md)
- `Resource`
- `ResourceWithArgs`
- `ResourceWithEndpoints`
- `ResourceWithEnvironment`
- `ResourceWithWaitSupport`

## Properties

- `ResourceTypeDisplayName`: `string` `get` -- Gets the ResourceTypeDisplayName property

## Methods

- [WithGradleBuild](/reference/api/go/aspire.hosting.java/javaappresource/withgradlebuild.md) -- `method` -- Runs a Gradle build before the Java application starts.
  ```go
  WithGradleBuild(args []string) JavaAppResource
  ```
- [WithGradleTask](/reference/api/go/aspire.hosting.java/javaappresource/withgradletask.md) -- `method` -- Launches the Java application through a Gradle task instead of `java`, for example `bootRun`.
  ```go
  WithGradleTask(task string, args []string) JavaAppResource
  ```
- [WithJarArtifact](/reference/api/go/aspire.hosting.java/javaappresource/withjarartifact.md) -- `method` -- Selects the JAR the generated container image runs, for projects whose build produces more than one.
  ```go
  WithJarArtifact(jarPath string) JavaAppResource
  ```
- [WithMainClass](/reference/api/go/aspire.hosting.java/javaappresource/withmainclass.md) -- `method` -- 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.
  ```go
  WithMainClass(mainClass string) JavaAppResource
  ```
- [WithMavenBuild](/reference/api/go/aspire.hosting.java/javaappresource/withmavenbuild.md) -- `method` -- Runs a Maven build before the Java application starts.
  ```go
  WithMavenBuild(args []string) JavaAppResource
  ```
- [WithMavenGoal](/reference/api/go/aspire.hosting.java/javaappresource/withmavengoal.md) -- `method` -- Launches the Java application through a Maven goal instead of `java`, for example `spring-boot:run`.
  ```go
  WithMavenGoal(goal string, args []string) JavaAppResource
  ```
- [WithOtelAgent](/reference/api/go/aspire.hosting.java/javaappresource/withotelagent.md) -- `method` -- Runs the application with the OpenTelemetry Java agent so it exports traces, metrics, and logs to Aspire.
  ```go
  WithOtelAgent(agentPath string) JavaAppResource
  ```
- [WithOtelAgentDefaultPath](/reference/api/go/aspire.hosting.java/javaappresource/withotelagentdefaultpath.md) -- `method` -- Runs the application with the OpenTelemetry Java agent from the location the build tool writes it to.
  ```go
  WithOtelAgentDefaultPath() JavaAppResource
  ```
- [WithWrapperPath](/reference/api/go/aspire.hosting.java/javaappresource/withwrapperpath.md) -- `method` -- Overrides the build tool wrapper script path, for repositories whose wrapper is not in the default location or does not use the default name.
  ```go
  WithWrapperPath(wrapperPath string) JavaAppResource
  ```
