# JavaAppResource.WithOtelAgentDefaultPath

- Module: [Aspire.Hosting.Java](/reference/api/go/aspire.hosting.java.md)
- Defined on: [JavaAppResource](/reference/api/go/aspire.hosting.java/javaappresource.md)
- Version: `17.0.0-preview.1.26565.2`
- Kind: `method`

Runs the application with the OpenTelemetry Java agent from the location the build tool writes it to.

## Remarks

The agent is expected at `target/agent/opentelemetry-javaagent.jar` for Maven and
`build/agent/opentelemetry-javaagent.jar` for Gradle -- the conventional output directory of each tool
with an `agent` subdirectory. The build has to put it there; nothing is downloaded. With Maven, copy it
with `maven-dependency-plugin`'s `copy` goal bound to `process-resources`; with Gradle,
declare the agent in its own configuration and add a `Copy` task that `compileJava` depends on.
May be called before or after the build tool is configured: which directory the agent is read from is
decided when the application model is built, so the result does not depend on the order of builder calls.
Because the build writes the agent, Aspire runs that build as its own resource in run mode and holds
the application until it finishes -- including for Spring Boot and Quarkus, whose launch goals would
otherwise be the only build. This is required rather than an optimization: `JAVA_TOOL_OPTIONS` is
read by every JVM started beneath the resource, and the first of those is the wrapper's own, so an
agent the build has not written yet kills that JVM during VM initialization with "Error opening zip
file or JAR manifest missing" before the launch goal runs.
Use `WithOtelAgent` when the agent lives anywhere else, including
when it is committed to the repository or supplied by the container base image.

## Definition

```go
type JavaAppResource interface {
    // ... omitted for brevity
    WithOtelAgentDefaultPath() JavaAppResource
}
```

## Signature

```go
WithOtelAgentDefaultPath() JavaAppResource
```

## Returns

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

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

## Defined on

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