# AddJavaContainer

- 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 from an existing container image.

## Remarks

Use this when the image is built elsewhere -- by a separate CI pipeline, or by a team that ships the
application as a container. Aspire runs the image as-is and never rebuilds it, so the JAR, the JDK,
and any OpenTelemetry agent all come from the image. Use
`AddJavaApp` instead when Aspire should
build and run the application from source.
No endpoint is declared, because the port the image listens on is a property of the image. Add one
with `WithHttpEndpoint(targetPort: 8080)`, using whichever port the application binds -- 8080
for a default Spring Boot or Quarkus image.

## Definition

```go
func (DistributedApplicationBuilder) AddJavaContainer(
    name string,
    image string,
    options ...*AddJavaContainerOptions,
) JavaContainerResource
```

## Parameters

- `name` (`string`) -- The name of the resource.
- `image` (`string`) -- The container image that runs the application, for example `mycompany/catalog`.
- `options` (`...*AddJavaContainerOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*AddJavaContainerOptions` argument.

- `Tag` (`*string`) -- The image tag. Defaults to the image's `latest` tag.

## Returns

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

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

## Applies to

- `DistributedApplicationBuilder`
