[Yandex Cloud documentation](../../../index.md) > [Yandex Cloud Registry](../../index.md) > [Step-by-step guides](../index.md) > Managing artifacts > Java artifact > Setting up Maven

# Setting up Maven

1. Create the following environment variables depending on the authentication method:
   
   {% list tabs group=registry_auth %}
   
   - IAM token {#iam-token}
   
     1. Get an [IAM token](../../../iam/concepts/authorization/iam-token.md) for the [Yandex account](../../../iam/operations/iam-token/create.md) or [service account](../../../iam/operations/iam-token/create-for-sa.md) you are going to use for authentication.
     1. Create the `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` environment variables:
   
         ```bash
         export REGISTRY_USERNAME="iam"
         export REGISTRY_PASSWORD="<IAM_token>"
         ```
   
         Where:
   
         * `REGISTRY_USERNAME`: Authentication method.
         * `REGISTRY_PASSWORD`: Body of the previously obtained IAM token.
   
     {% note info %}
   
     The IAM token's [lifetime](../../../iam/concepts/authorization/iam-token.md#lifetime) is limited to 12 hours.
   
     {% endnote %}
   
   - API key {#api-key}
   
     1. [Create](../../../iam/operations/authentication/manage-api-keys.md#create-api-key) an API key for the [service account](../../../iam/concepts/users/service-accounts.md) you are going to use for authentication.
     1. Create the `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` environment variables:
   
         ```bash
         export REGISTRY_USERNAME="api_key"
         export REGISTRY_PASSWORD="<API_key>"
         ```
   
         Where:
   
         * `REGISTRY_USERNAME`: Authentication method.
         * `REGISTRY_PASSWORD`: Body of the previously created [API key](../../../iam/concepts/authorization/api-key.md).
   
     {% note info %}
   
     The API key maximum [lifetime](../../../iam/concepts/authorization/api-key.md#scoped-api-keys) is set manually when you create the key.
   
     {% endnote %}
   
   {% endlist %}
1. Open the file with the global Maven settings.

    By default, the configuration file is located in the current user's `.m2` directory (`~/.m2/settings.xml` for Unix-like OSes and `%USERPROFILE%\.m2\settings.xml` for Windows). Learn more about the configuration file structure in [this Maven guide](https://maven.apache.org/settings.html).

1. Add a new repository to the `repositories` section of the Maven settings file:

    ```xml
    <repository>
        <id>local</id>
        <url>registry.yandexcloud.net/maven/<registry_ID></url>
    </repository>
    ```

1. Add a new server to the `servers` section of the Maven settings file:

    ```xml
    <server>
        <id>local</id>
        <username>${env.REGISTRY_USERNAME}</username>
        <password>${env.REGISTRY_PASSWORD}</password>
    </server>
    ```