# JavaAppResource

- Module: [Aspire.Hosting.Java](/reference/api/typescript/aspire.hosting.java.md)
- Version: `13.6.0-preview.1.26478.8`
- Kind: `handle`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62)

Represents a Java application resource in the distributed application model.

## Definition

```typescript
interface JavaAppResource
  extends IComputeResource,
    IContainerFilesDestinationResource,
    IResource,
    IResourceWithArgs,
    IResourceWithEndpoints,
    IResourceWithEnvironment,
    IResourceWithProbes,
    IResourceWithWaitSupport,
    IResourceWithServiceDiscovery,
    IJavaAppResource {
  withGradleBuild(args: string[]): JavaAppResource;
  withGradleTask(
      task: string,
      args: string[]): JavaAppResource;
  withJarArtifact(jarPath: string): JavaAppResource;
  withMainClass(mainClass: string): JavaAppResource;
  withMavenBuild(args: string[]): JavaAppResource;
  withMavenGoal(
      goal: string,
      args: string[]): JavaAppResource;
  withOtelAgent(agentPath: string): JavaAppResource;
  withOtelAgentDefaultPath(): JavaAppResource;
  withWrapperPath(wrapperPath: string): JavaAppResource;
}
```

## Methods

- [withGradleBuild](/reference/api/typescript/aspire.hosting.java/javaappresource/withgradlebuild.md) -- `method` -- Runs a Gradle build before the Java application starts.
    ```typescript
  withGradleBuild(args: string[]): JavaAppResource
  ```
- [withGradleTask](/reference/api/typescript/aspire.hosting.java/javaappresource/withgradletask.md) -- `method` -- Launches the Java application through a Gradle task instead of `java`, for example `bootRun`.
    ```typescript
  withGradleTask(task: string, args: string[]): JavaAppResource
  ```
- [withJarArtifact](/reference/api/typescript/aspire.hosting.java/javaappresource/withjarartifact.md) -- `method` -- Selects the JAR the generated container image runs, for projects whose build produces more than one.
    ```typescript
  withJarArtifact(jarPath: string): JavaAppResource
  ```
- [withMainClass](/reference/api/typescript/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.
    ```typescript
  withMainClass(mainClass: string): JavaAppResource
  ```
- [withMavenBuild](/reference/api/typescript/aspire.hosting.java/javaappresource/withmavenbuild.md) -- `method` -- Runs a Maven build before the Java application starts.
    ```typescript
  withMavenBuild(args: string[]): JavaAppResource
  ```
- [withMavenGoal](/reference/api/typescript/aspire.hosting.java/javaappresource/withmavengoal.md) -- `method` -- Launches the Java application through a Maven goal instead of `java`, for example `spring-boot:run`.
    ```typescript
  withMavenGoal(goal: string, args: string[]): JavaAppResource
  ```
- [withOtelAgent](/reference/api/typescript/aspire.hosting.java/javaappresource/withotelagent.md) -- `method` -- Runs the application with the OpenTelemetry Java agent so it exports traces, metrics, and logs to Aspire.
    ```typescript
  withOtelAgent(agentPath: string): JavaAppResource
  ```
- [withOtelAgentDefaultPath](/reference/api/typescript/aspire.hosting.java/javaappresource/withotelagentdefaultpath.md) -- `method` -- Runs the application with the OpenTelemetry Java agent from the location the build tool writes it to.
    ```typescript
  withOtelAgentDefaultPath(): JavaAppResource
  ```
- [withWrapperPath](/reference/api/typescript/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.
    ```typescript
  withWrapperPath(wrapperPath: string): JavaAppResource
  ```
