opendataloader-project/opendataloader-pdf · error · RuntimeError

Could not find the JAR file. Please run 'mvn package' in the

Error message

Could not find the JAR file. Please run 'mvn package' in the 'java/' directory first. Searched in: {resolved_glob_path}

What it means

RuntimeError raised by the hatch build hook when glob.glob found ZERO jars matching java/opendataloader-pdf-cli/target/opendataloader-pdf-cli-*.jar. The Python wheel packages the prebuilt CLI jar, so the hook requires that Maven has already produced it. The message prints the resolved glob path so you can see exactly where it looked.

Source

Thrown at python/opendataloader-pdf/hatch_build.py:47

            and license_path.exists()
            and notice_path.exists()
            and third_party_dest.exists()
            and readme_path.exists()
        ):
            print("All required files already exist (building from sdist), skipping copy")
            return

        # --- Copy JAR ---
        print(f"Root DIR: {root_dir}")
        source_jar_glob = str(
            root_dir / "../../java/opendataloader-pdf-cli/target/opendataloader-pdf-cli-*.jar"
        )
        resolved_glob_path = Path(source_jar_glob).resolve()
        print(f"Searching for JAR file in: {resolved_glob_path}")

        source_jar_paths = glob.glob(source_jar_glob)
        if not source_jar_paths:
            raise RuntimeError(
                f"Could not find the JAR file. Please run 'mvn package' in the 'java/' directory first. Searched in: {resolved_glob_path}"
            )
        if len(source_jar_paths) > 1:
            raise RuntimeError(f"Found multiple JAR files, expected one: {source_jar_paths}")
        source_jar_path = source_jar_paths[0]
        print(f"Found source JAR: {source_jar_path}")

        dest_jar_dir.mkdir(parents=True, exist_ok=True)
        print(f"Copying JAR to {dest_jar_path}")
        shutil.copy(source_jar_path, dest_jar_path)

        # --- Copy LICENSE, NOTICE ---
        # README is copied by build-python.sh before this hook runs, because
        # hatchling validates [project.readme] during metadata parsing, which
        # happens before build hooks. Do not copy README here.
        shutil.copy(root_dir / "../../LICENSE", license_path)
        shutil.copy(root_dir / "../../NOTICE", notice_path)
        third_party_src = root_dir / "../../THIRD_PARTY"

View on GitHub (pinned to a7789b8e77)

Solutions

  1. Build the jar first: run mvn package (or mvn -DskipTests package) in the java/ directory, then rebuild the wheel.
  2. Confirm the produced jar path matches the glob: ls java/opendataloader-pdf-cli/target/opendataloader-pdf-cli-*.jar.
  3. In CI, order the Maven build step before the Python build step and fail fast if Maven fails.
  4. If building from sdist, ensure the sdist was generated after a successful Maven build.

Example fix

# before: wheel build with no jar
$ pip install .  # -> RuntimeError: Could not find the JAR file...
# after: build jar first, then wheel
$ (cd java && mvn -DskipTests package)
$ pip install .
Defensive patterns

Strategy: validation

Validate before calling

# Pre-build check in your build script:
from pathlib import Path
import glob
jar = glob.glob("java/opendataloader-pdf-cli/target/opendataloader-pdf-cli-*.jar")
assert len(jar) == 1, f"Expected exactly 1 jar, found {len(jar)}; run: (cd java && mvn -DskipTests package)"

Type guard

def is_missing_jar_error(exc: RuntimeError) -> bool:
    return isinstance(exc, RuntimeError) and "Could not find the JAR file" in str(exc)

Try / catch

# In CI: build jar first, fail fast if absent, then build the wheel.
#   (cd java && mvn -DskipTests package) && pip install .
# If hit at runtime:
try:
    import opendataloader_pdf
except RuntimeError as e:
    if "Could not find the JAR file" in str(e):
        raise SystemExit("Run (cd java && mvn package) then reinstall")
    raise

Prevention

When it happens

Trigger: Running pip install / hatch build / python -m build on the opendataloader-pdf package WITHOUT having first run mvn package in the java/ directory, so target/ has no jar (or target/ does not exist).

Common situations: Fresh clone where only the Python package is being built. CI that builds the wheel before the Maven step. Building from an sdist that did not include the jar. A clean that wiped target/.

Related errors


AI-assisted analysis of opendataloader-project/opendataloader-pdf@a7789b8e77 (2026-08-14). Data as JSON: /api/errors/a62211819f168cd1. Report an issue: GitHub.