# AddJavaApp

- Module: [Aspire.Hosting.Java](/reference/api/go/aspire.hosting.java.md)
- Version: `17.0.0-preview.1.26567.5`
- Kind: `method`
- Defined on: `DistributedApplicationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Adds a Java application to the application model, launched with `java`.

## Remarks

Combine with `WithMavenGoal` or
`WithGradleTask` to run the application through a build tool,
or use the overload that accepts a `jarPath` to run a prebuilt JAR with `java -jar`.
Exactly one of those three launch modes must be configured.

## Definition

```go
func (DistributedApplicationBuilder) AddJavaApp(
    name string,
    appDirectory string,
) JavaAppResource
```

## Parameters

- `name` (`string`) -- The name of the resource.
- `appDirectory` (`string`) -- The application directory. Relative paths are resolved against the AppHost directory.

## Returns

[`JavaAppResource`](/reference/api/go/aspire.hosting.java/javaappresource.md) -- A reference to the `IResourceBuilder`.

Returns a handle; failures surface later via `Err()`.

## Applies to

- `DistributedApplicationBuilder`
