testcontainers/testcontainers-java · error · ContainerLaunchException

License file ' ' does not exist.

Error message

License file '${mountableLicense.getFilesystemPath()}' does not exist.

What it means

withLicense(MountableFile) resolves the license file path on the host and checks that it exists before mounting it into the HiveMQ container at /opt/hivemq/license. If the resolved path does not exist on the host filesystem, a ContainerLaunchException is thrown immediately, before the container starts.

Solutions

  1. Verify the license file path exists on the host (new File(path).exists()) before calling withLicense.
  2. Use an absolute path or Mountable.forHostFile with the correct path.
  3. In CI, ensure the .lic/.elic license file is provisioned (secret mount, artifact download) before tests run.
  4. Check the working directory that relative paths resolve against.

Example fix

// before
container.withLicense(MountableFile.forHostPath("/opt/hivemq/license.lic")); // file missing
// after
File lic = new File("/opt/hivemq/license.lic");
if (!lic.exists()) throw new IllegalStateException("License missing: " + lic);
container.withLicense(MountableFile.forHostPath(lic.getAbsolutePath()));
Defensive patterns

Strategy: validation

Validate before calling

File lic = new File(licensePath);
if (!lic.exists()) throw new IllegalStateException("License file not found: " + lic.getAbsolutePath());

Try / catch

try { container.withLicense(MountableFile.forHostPath(licensePath)); } catch (ContainerLaunchException e) { log.error("License missing: {}", e.getMessage()); throw e; }

Prevention

When it happens

Trigger: Calling container.withLicense(MountableFile.forHostPath(...)) with a path that does not exist on the host machine.

Common situations: Typo in the license file path; license file present in CI but not committed/mounted into the build environment; relative path resolved against a different working directory; license stored in a secret that was not mounted in the test environment.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/4f572d9b5a2b06de. Report an issue: GitHub.

Appendix: source

Thrown at modules/hivemq/src/main/java/org/testcontainers/hivemq/HiveMQContainer.java:316

     */
    public @NotNull HiveMQContainer withoutPrepackagedExtensions() {
        removeAllPrepackagedExtensions = true;
        return self();
    }

    /**
     * Puts the given license into '/opt/hivemq/license/' inside the container.
     * It must end with '.lic' or '.elic'.
     * <p>
     * Must be called before the container is started.
     *
     * @param mountableLicense the license file on the host machine
     * @return self
     */
    public @NotNull HiveMQContainer withLicense(final @NotNull MountableFile mountableLicense) {
        final File licenseFile = new File(mountableLicense.getResolvedPath());
        if (!licenseFile.exists()) {
            throw new ContainerLaunchException(
                "License file '" + mountableLicense.getFilesystemPath() + "' does not exist."
            );
        }
        if (!licenseFile.getName().endsWith(".lic") && !licenseFile.getName().endsWith(".elic")) {
            throw new ContainerLaunchException(
                "License file '" + mountableLicense.getFilesystemPath() + "' does not end wit '.lic' or '.elic'."
            );
        }
        final String containerPath = "/opt/hivemq/license/" + licenseFile.getName();
        withCopyFileToContainer(cloneWithFileMode(mountableLicense), containerPath);
        LOGGER.info("Putting license '{}' into '{}'.", licenseFile.getAbsolutePath(), containerPath);
        return self();
    }

    /**
     * Overwrites the HiveMQ configuration in '/opt/hivemq/conf/' inside the container.
     * <p>
     * Must be called before the container is started.

View on GitHub (pinned to 8e549514e3)