> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Building and deploying the solution

## Building the project

### Maven repositories

1. From the [ActiveViam share](https://artifacts.activeviam.com/share/ActivePivot_stable/) page,
   download the Maven repository for the version of Atoti Server the
   Solution is based on (will be specified in the release notes of
   the Solution you are deploying). The zip file containing the
   Maven repository will be called *maven-repository-**\<version
   number>**.zip*.
2. On the Atoti CVA Risk Capital [Release
   Notes](../../dev-release/release-notes) page, follow
   the directions to the *Distribution Files* section and download the
   Maven repository for the Solution (contains all dependencies
   required to build the Solution that aren't included in the
   Atoti Server download). A zip file containing the Maven repository
   will be called *cvarc-accelerator-**\<version
   number>**-maven-repository.zip*.

   Add these repositories to your existing Maven repository.

### Set up Artifactory access

In addition to the repository zips, you can download all of the Maven dependencies from Artifactory by setting up your Maven settings file like so:

```xml theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
<settings>
    <profiles>
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

            <repositories>
                <repository>
                    <id>ActiveViamInternalRepository</id>
                    <name>ActiveViam Internal Repository</name>
                    <url>https://activeviam.jfrog.io/activeviam/activeviam-mvn-accelerators/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>

    <servers>
        <server>
            <id>ActiveViamInternalRepository</id>
            <username>username</username>
            <password>password</password>
        </server>
    </servers>
</settings>
```

In order to download the dependencies for the UI, it is **required** to set up access to Artifactory via npm, like so:

`npm login --scope @activeviam --registry https://activeviam.jfrog.io/artifactory/api/npm/activeviam-npm-accelerators/`

The result should be the following message:
`Logged in as username to scope @activeviam on https://activeviam.jfrog.io/artifactory/api/npm/activeviam-npm-accelerators/.`

If the scope isn't mentioned in the message, they might have to change the command to:
`npm login --scope=@activeviam --registry=https://activeviam.jfrog.io/artifactory/api/npm/activeviam-npm-accelerators/`

### Source

Download and unzip the source zip from the [Artifactory](https://activeviam.jfrog.io/artifactory/activeviam-accelerators-artifacts/cvarc/) page.

### Build

<Note>
  Java 21 is now required to run Atoti CVA Risk Capital (as of version 6.0.0). Previous versions (5.1.x) required Java 17.
</Note>

1. In order to compile the source code using Maven, you must set your `MAVEN_OPTS` environment variable, like so: `MAVEN_OPTS="-Xms1024m -Xmx2048m -Xss5m"`
2. Once you have added all the Maven repositories and extracted the
   source code, run `mvn install` on the parent pom file to build the
   entire project.

   This will build the Atoti Server executable JAR file
   (cvarc-application/target/cvarc-application-exec.jar).
3. When the build is complete, you must deploy it. See
   [Deployment](#Deployment).
4. Build the standalone UI application using npm or yarn.
5. Deploy the UI application.

## Configuration

The only configuration required to start is to edit `cvarc-application/src/main/resources/properties/cvarc.properties`

Set `csv-source.dataset` to the directory you want to put your data.

## Alternatives

1. If you only want to use the sample data embedded in the project along with the Jetty server, then you don't need to configure the data directory.
2. You can copy the sample data (`cvarc-application-tests/src/test/resources/data-samples/data/`) into `cvarc-application/src/main/resources/` then the sample data will be included in the .jar file and you won't need to set the data directory.

See [Project configuration](./configuration-project).

## Deployment

### Atoti Server

The cvarc-application is a Spring Boot application that builds to an executable JAR. To deploy the
executable JAR file, simply use the following command:

```
java --add-opens java.base/java.util.concurrent=ALL-UNNAMED -jar cvarc-application-exec.jar
```

<Note>
  The default port for cvarc-application is 9090.

  Atoti Server will be available at: *http\://\<your hostname>:9090/cvarc-application/*
</Note>

You can change the port by either of the following:

* Use the argument `server.port`.

  For example:

```
java --add-opens java.base/java.util.concurrent=ALL-UNNAMED -jar cvarc-application-exec.jar --server.port=<port>
```

* Externalize the properties files (see [Externalizing Properties
  Files](#Externalizing_Properties_Files) )

### \[Eclipse / IntelliJ] + Jetty

<Warning>
  You may run into a Java.Lang.StackOverflow exception due to an unresolved Oracle issue when attempting to build the project, detailed stack trace in [CVARC-275](https://support.activeviam.com/jira/browse/CVARC-275). If this occurs, then you will need to add the following PATH variable to increase the memory available to Maven during build processes.

  `MAVEN_OPTS="-Xms2048m -Xmx4096m -Xss8m"`
</Warning>

* Use Maven to run an initial build of the Accelerator `$ mvn clean install`.
* Start the server by running `CVARCApplication.java` in `cvarc-application/src/main/java/com/activeviam/cvarc/application`.
* The server will run at [https://localhost:9090/cvarc-application](https://localhost:9090/cvarc-application)
* You will need to compile and serve up the ui from the ui source code, as described in the [Atoti UI](#atoti-ui) section.

#### Extra steps to run in IntelliJ

To successfully run CVA Risk Capital inside IntelliJ, you need to allocate more memory to the IntelliJ compiler. Add the necessary memory flags inside the 'User-local build process VM options' field found here:

`Preferences | Build, Execution, Deployment | Compiler | 'User-local build process VM options'`.

Example value: `-Xms2048m -Xmx4096m -Xss8m`

Set the values to allocate enough memory to the compiler considering the amount of RAM available in your machine.

#### Extra steps to run in Eclipse

To Successfully run CVA Risk Capital inside Eclipse, you will need to allocate more memory to the Eclipse Maven Build:

`-Xms1024m -Xmx2048m -Xss5m`

<Frame>
  <img src="https://mintcdn.com/activeviam/43bi0pL0XluM4I2q/solutions/cva-risk-capital/6.0/images/eclipse-jrevmargs.png?fit=max&auto=format&n=43bi0pL0XluM4I2q&q=85&s=5e4b19400eb700076c7cdf22cab5fd31" alt="Eclipse JRE VM Args" width="1353" height="928" data-path="solutions/cva-risk-capital/6.0/images/eclipse-jrevmargs.png" />
</Frame>

## How to run all tests

`mvn clean install -P IT`

### Atoti UI

Atoti UI is a static website that can be deployed in any way you see
fit. All the necessary files are to be found in the *./build* folder of
the standalone application after the project has been built.

As an example, the UI can be deployed on Tomcat using the following
instructions:

1. Build the standalone application:

   1. Set up artifactory access for node dependencies
   2. Download the ui source code from [artifactory](https://activeviam.jfrog.io/artifactory/activeviam-accelerators-artifacts/cvarc/).
   3. Copy the lockfile for the build tool you use (i.e. package-lock.json for npm, yarn.lock for yarn) into the project's main directory.
   4. Run `npm ci` if using npm, or `yarn install --frozen-lockfile` if using yarn.
   5. Run `npm run build` if using npm, or `yarn build` if using yarn.
2. Place the deployment in the *webapps* folder of your Tomcat:

   1. Find where the *webapps* folder is for your Tomcat.
   2. Create a folder called *cvarc-activeui* in the Tomcat *webapps*
      folder.
   3. Copy the contents from the build folder into your new folder
      *webapps/cvarc-activeui/*.
3. Start the Tomcat server. You can now access the UI on the
   address *http\://\<your hostname>:\<port>/cvarc-activeui/.*

## Externalizing properties files

In the default implementation, all the necessary properties are within
the project. A number of properties files have been externalized and can
be overridden with an external file using JVM variables. You may wish to
use this functionality if you are running the project in different
environments. Below is a list of the files together with their
respective variable names:

There are three options to override default properties:

* OPTION 1: Command line arguments, e.g. `--csv-source.dataset=/path/to/folder`.

<Note>
  We use "--" to set properties with Spring Boot.
</Note>

* OPTION 2: Create a properties file (e.g. `application.properties`) and add your property
  overrides. Then pass it to the main using the command line argument `--spring.config.additional-location=/<path>/application.properties`
* OPTION 3: Change the path to the default properties file using the
  appropriate variable specified below:

| File                 | Variable Name                      |
| -------------------- | ---------------------------------- |
| cvarc.properties     | app.env.properties.file.path       |
| hibernate.properties | hibernate.env.properties.file.path |

If any of the above variables are not set, the default properties
files will be used.

Example values for these properties files include:

* `classpath:<filename>`
* `file:/home/etc/<filename>` - Unix Environment
* `file:///C:/Users/john/config/<filename>` - Windows environment

<Tip>
  Options 1 and 2 are recommended because they only override the
  properties you specify and use the defaults for other ones.
  Additionally, they can be used to override any property.

  Option 3 only works for specific properties files (i.e. the ones
  specified in the table above), and replaces the default file completely,
  meaning you need to make a copy of the default file and have all
  properties in your external custom file even if they have the same value
  as the default file.
</Tip>
