# Coverage Reporting for Embedded Java Libraries

## **Problem**

When Java applications include multiple embedded components—such as shared libraries packaged inside EAR/WAR files—coverage may not appear for those components because the agent cannot attribute coverage without multi‑component configuration.

## **Solution**

{% hint style="info" %}
Coverage cannot be accurately reported if two different versions of the **same component** run within the same deployed application.
{% endhint %}

{% stepper %}
{% step %}

### **Prerequisites**

Make sure:

1. Each component **is built in its own pipeline** (unique Build Session ID).
2. Each component **contains its specific  `buildSessionId.txt`** inside the packaged JAR/WAR - Build step uses `includeResources: true` (or leave it out—the default is true)..
3. Final application (EAR/WAR) **preserves** **embedded artifacts unchanged**.
   {% endstep %}

{% step %}

### Required Runtime Configuration

Add these JVM flags to the application under test:

```
-Dsl.multipleComponents=true \
-Dsl.webappLocation=<absolute-path-to-deployment-directory>
```

According to your deployment methodology:

* If the application is deployed in an exploded form, the `sl.webappLocation` property must point to the exploded directory.&#x20;
* If the application is not exploded, `sl.webappLocation` should instead point to the directory that contains the EAR or WAR file, rather than the file itself.

If your embedded libraries use package names outside the main application’s namespace, you must explicitly include them:

```
-Dsl.includes=com.company.app.*,com.company.lib.*
```

{% endstep %}
{% endstepper %}

{% hint style="success" %}
You are correctly configured when:

* [ ] Each embedded component appears as a **separate item** in the SeaLights dashboard.
* [ ] During runtime, the Cockpit > Live Agents page shows both the embedded libraries and the applications reporting from the same machine.
* [ ] Coverage is reported **per component**, not only at the application level.
* [ ] No warnings about missing Build Session IDs.
  {% endhint %}

### Common issues

* Only top-level app visible in Live Agents → `sl.multipleComponents=true` not set
* Agent warns about components not detected → Wrong `sl.webappLocation`
* Component shows 0% coverage → `buildSessionId.txt` missing
