# WithJarArtifact

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

Selects the JAR the generated container image runs, for projects whose build produces more than one.

## Remarks

Only affects publishing, and only when the application is built in the image. Without it the
container build selects the single JAR that is not a `-plain`, `-sources`, or
`-javadoc` artifact, and fails the build if that is ambiguous.
This takes precedence over the JAR named by the `jarPath` overload of
`AddJavaApp`, so a
resource can run one JAR locally and publish another. It has no effect on an application published
from a prebuilt JAR, because nothing is built in the image for it to select from.

## Definition

```go
func (JavaAppResource) WithJarArtifact(jarPath string) JavaAppResource
```

## Parameters

- `jarPath` (`string`) -- The path to the JAR produced by the build, relative to the application directory, for example `target/app.jar`.

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

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