testcontainers/testcontainers-java · error · ContainerLaunchException
File ' ' does not exist.
Error message
File '${mountableFile.getFilesystemPath()}' does not exist. What it means
withFileInHomeFolder resolves the MountableFile path on the host and requires the file to exist before copying it into /opt/hivemq + pathInHomeFolder in the container. A non-existent host file results in a ContainerLaunchException thrown before the container starts.
Solutions
- Verify the host file exists before the call and fail fast with a clear message.
- Use an absolute path resolved from the classpath or project root.
- In CI, ensure the file is generated/copied into the workspace before tests execute.
- If the resource is inside a JAR, extract it to a temp file and mount that.
Example fix
// before
container.withFileInHomeFolder(MountableFile.forHostPath("target/extra.xml"), "/extension/x/");
// after
File f = new File("target/extra.xml");
if (!f.exists()) throw new IllegalStateException("Missing: " + f);
container.withFileInHomeFolder(MountableFile.forHostPath(f.getAbsolutePath()), "/extension/x/"); Defensive patterns
Strategy: validation
Validate before calling
File f = new File(hostPath);
if (!f.exists()) throw new IllegalStateException("Host file missing: " + f.getAbsolutePath());
if (pathInHomeFolder == null || pathInHomeFolder.isBlank()) throw new IllegalArgumentException("pathInHomeFolder required"); Try / catch
try { container.withFileInHomeFolder(mountable, path); } catch (ContainerLaunchException e) { log.error("Mount failed: {}", e.getMessage()); throw e; } Prevention
- Extract classpath resources inside JARs to temp files before mounting.
- Generate required files in a test setup step that fails loudly if skipped.
- Use absolute paths anchored to the project root.
When it happens
Trigger: Calling container.withFileInHomeFolder(MountableFile.forHostPath(missing), path) — directly or via withFileInExtensionHomeFolder — where the host file does not exist.
Common situations: File produced by a prior test/build step that failed or did not run; wrong resource path in CI; file deleted between resolution and call; classpath resource assumed to be a real file but packed inside a JAR.
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
- Extension ' ' could not be mounted. It does not exist.
- License file ' ' does not exist.
- HiveMQ config file ' ' does not exist.
- Could not find unix domain socket
- Extension ' ' could not be mounted. It is not a directory.
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/8ef62e3e7aa2a871.
Report an issue: GitHub.
Appendix: source
Thrown at modules/hivemq/src/main/java/org/testcontainers/hivemq/HiveMQContainer.java:413
* <p>
* Must be called before the container is started.
*
* @param mountableFile the file on the host machine
* @param pathInHomeFolder the path
* @return self
*/
public @NotNull HiveMQContainer withFileInHomeFolder(
final @NotNull MountableFile mountableFile,
final @NotNull String pathInHomeFolder
) {
final File file = new File(mountableFile.getResolvedPath());
if (pathInHomeFolder.trim().isEmpty()) {
throw new ContainerLaunchException("pathInHomeFolder must not be empty");
}
if (!file.exists()) {
throw new ContainerLaunchException("File '" + mountableFile.getFilesystemPath() + "' does not exist.");
}
final String containerPath = "/opt/hivemq" + PathUtil.prepareAppendPath(pathInHomeFolder);
withCopyFileToContainer(cloneWithFileMode(mountableFile), containerPath);
LOGGER.info("Putting file '{}' into container path '{}'.", file.getAbsolutePath(), containerPath);
return self();
}
/**
* Disables the extension with the given name and extension directory name.
* This method blocks until the HiveMQ log for successful disabling is consumed or it times out after {timeOut}.
* Note: Disabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.
* <p>
* This can only be called once the container is started.
*
* @param extensionName the name of the extension to disable
* @param extensionDirectory the name of the extension's directory
* @param timeout the timeout
* @throws TimeoutException if the extension was not disabled within the configured timeoutView on GitHub (pinned to 8e549514e3)