# AddJavaAppWithJar

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

Adds a Java application that runs a prebuilt JAR with `java -jar`.

## Definition

```go
func (DistributedApplicationBuilder) AddJavaAppWithJar(
    name string,
    appDirectory string,
    jarPath string,
    args []string,
) JavaAppResource
```

## Parameters

- `name` (`string`) -- The name of the resource.
- `appDirectory` (`string`) -- The application directory. Relative paths are resolved against the AppHost directory.
- `jarPath` (`string`) -- The path to the JAR file to execute. Relative paths are resolved against `appDirectory`.
- `args` (`[]string`) -- Arguments passed to the Java application after the JAR path.

## 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`
