# WithJvmArgs

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

Adds arguments to the Java Virtual Machine that runs the application.

## Remarks

Arguments are passed through the `JAVA_TOOL_OPTIONS` environment variable, which the JVM reads
however it was started -- `java -jar`, a Maven goal, a Gradle task, or a container image's own
entrypoint, including the JVM those build tools fork. Values containing spaces are quoted, because
the JVM splits this variable on whitespace.
This is also how a container image that already carries the OpenTelemetry Java agent turns it on,
since `WithOtelAgent` copies an agent from the build
context and so applies only to applications Aspire itself launches or builds:
`WithJvmArgs("-javaagent:/app/opentelemetry-javaagent.jar")`.

## Definition

```go
func (IJavaAppResource) WithJvmArgs(args []string) IJavaAppResource
```

## Parameters

- `args` (`[]string`) -- The JVM arguments, for example `-Xmx512m`.

## Returns

[`IJavaAppResource`](/reference/api/go/aspire.hosting.java/ijavaappresource.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)
- [`JavaContainerResource`](/reference/api/go/aspire.hosting.java/javacontainerresource.md)
