Introducing a new way to review your PRs.

Read the announcement

maplibre / maplibre-tile-spec

Next generation map vector tiles format

View on GitHub

20 documents · Updated Nov 23, 2026

docs / java-cli-and-tools

Java CLI and tools

The Java command-line and utility modules give users practical ways to convert, inspect, validate, and generate MapLibre Tile (MLT) data. The CLI extends the Java tile library with user-facing workflows and uses the Java core codec for tile work, while the tools module creates controlled MLT fixtures for development and cross-implementation checks.

User-facing operations

Encoding interface

The encode command turns one MVT tile or a tile container into MLT output. It accepts local files and PMTiles locations, then applies one conversion policy to the selected tiles. Users can choose an output file or directory and can limit batch work by zoom range or layer.

The command also exposes quality and size controls without requiring users to call the core library directly. These controls cover feature IDs, layer selection, column grouping, geometry preparation, integer and string compression, output compression, and parallel work. The accepted output compression choices depend on the selected input container.

Input formMain resultScope
Individual MVT fileIndividual MLT fileOne tile
MBTiles fileMLT MBTiles fileSQLite tile set
Offline databaseUpdated copy of the databaseExisting database schema
PMTiles file or URIMLT PMTiles fileLocal or range-readable archive

References: java/…/Encode.kt• L28-234 java/…/EncodeCommandLine.kt• L92-165 java/…/EncodeCommandLine.kt• L468-505

Decoding interface

The decode command reads an MLT tile and turns it into a JSON view for inspection. It can repeat the decode to measure time, which makes it useful for quick checks of tile contents and decode cost rather than for bulk conversion.

The encode command can use the same decode path after conversion. This lets a user print the round-tripped MLT or MVT view and compare geometry or properties with the source tile.

References: java/…/Decode.kt• L17-103 java/…/Encode.kt• L293-329 java/…/EncodeCommandLine.kt• L381-467

Conversion flow

The conversion flow reads source tile bytes, creates the tile description needed by the codec, encodes MLT bytes, and optionally checks the result. Container modes add tile selection, metadata handling, and archive writing around the same per-tile conversion.

This diagram shows how both single-tile and container inputs reach the shared conversion path.

flowchart LR
    A[ MVT tile ] --> C[Read and decode source]
    B[MBTiles, offline DB, or PMTiles] --> S[Select tiles and metadata]
    S --> C
    C --> E[Encode MLT]
    E --> Q[Optional compression]
    Q --> O[Write MLT tile or archive]
    E --> V[Optional decode, print, time, or compare]

The CLI reports failures through its process result and log output. Batch modes can stop on the first failure or continue where possible, so callers must choose the error policy when they need a complete archive or a best-effort conversion.

References: java/…/Conversion.kt• L172-307 java/…/EncodeCommandLine.kt• L565-624

Container workflows

MBTiles conversion produces a new SQLite tile set and carries source metadata into the result. Offline database conversion keeps the source database structure by updating tile records in a copied file. PMTiles conversion reads tile ranges from a local file or URI and writes a new archive with MLT format metadata and the resolved tile compression.

PMTiles work can use zoom bounds, parallel tasks, range caching, and content reuse. The reader groups coordinates that share a source byte range, and the writer reuses converted content for repeated ranges. These features reduce repeated reads and repeated writes for large archives, while the format check prevents non-MVT PMTiles input from entering the MVT-to-MLT conversion path.

References: java/…/MBTiles.kt• L24-29 java/…/OfflineDB.kt• L23-28 java/…/PMTiles.kt• L127-179 java/…/PMTiles.kt• L244-273

Remote archive access

PMTiles input is treated as a range-readable archive. The reader resolves tile coordinates through the archive directory, loads only the needed byte ranges, and exposes ranges of repeated tile content as one conversion unit. This supports local files and storage locations that provide byte-range reads.

The archive reader also carries archive metadata into the output. Its tile-coordinate range view lets the converter apply zoom limits before it schedules tile work.

References: java/…/ReadablePmtiles.kt• L17-20 java/…/ReadablePmtiles.kt• L66-103 java/…/ReadablePmtiles.kt• L192-223

Analysis and control

Validation controls

The CLI provides checks that compare the decoded result with the source. Users can check geometry, properties, or both. They can also ask the command to decode after a single-tile encode, print JSON views, and report elapsed time.

These controls serve two different needs: comparison checks protect conversion fidelity, while printing and timing help an engineer inspect or measure a tile. They do not replace the core codec's normal decode contract.

References: java/…/EncodeCommandLine.kt• L381-467 java/…/Conversion.kt• L285-301

Conversion policy

Command options map user choices into one conversion policy before tile work starts. The policy can preserve or remove IDs, handle property type mismatches by failing, coercing, or eliding values, select layer patterns, and request geometry or column optimizations.

The CLI validates the input mode and incompatible output choices before conversion. It also validates regular expressions, tessellation URLs, and compression names so that a bad request fails before it creates a partial result. PMTiles conversion then resolves absent compression settings from the source archive and carries the result into output metadata.

References: java/…/EncodeCommandLine.kt• L567-624 java/…/EncodeCommandLine.kt• L693-785 java/…/PMTiles.kt• L153-179

Parallel processing

Batch conversion can run tile tasks in parallel while keeping the work queue bounded. The queue limit can be tuned with MLT_THREAD_QUEUE_SIZE; when the queue is full, work runs in the caller instead of growing memory without limit. A serial mode remains available when parallel work is not requested.

Archive writers are shared resources, so the batch paths protect writes while allowing conversion work to run concurrently. The command waits for all scheduled work before it finalizes an output archive.

References: java/…/TaskRunner.kt• L7-45 java/…/MBTiles.kt• L75-146 java/…/PMTiles.kt• L181-215 java/…/PMTiles.kt• L440-449

Encoding service

The encode entry point can run as a small socket service. A client sends one command line and the service passes it through the same command parser as direct CLI use. This provides a simple way to submit repeated conversion requests without starting a new process for each request.

The service checks the requested port before it starts. It does not define a separate request format or a separate conversion feature set.

References: java/…/Server.kt• L10-60 java/…/Encode.kt• L36-49

Utility generation

Synthetic MLT fixtures

The mlt-tools module generates small, named MLT fixtures from controlled geometry, IDs, and property values. The fixtures cover normal tile content and combinations that are useful for checking codec behavior across supported encodings.

The generator writes both binary MLT data and a decoded JSON view. It forces the requested encoding choices instead of allowing size heuristics to replace them. It decodes each generated tile and compares the result with the expected view before it writes the fixture, so the output acts as a repeatable contract for codec changes.

References: java/…/SyntheticMltGenerator.java• L57-93 java/…/SyntheticMltUtil.java• L312-367

Fixture coverage

The utility set is aimed at edge conditions that are hard to inspect in large real tiles. Its generated cases include:

  • Point, line, polygon, and multi-geometry shapes.
  • Polygon holes, mixed geometry layers, and tessellated variants.
  • Feature IDs and missing IDs.
  • Numeric, string, boolean, null, and mixed properties.
  • Integer encodings, string compression, shared dictionaries, and Morton ordering.
  • Tile extents and byte-alignment cases for encoded integer streams.

The generator owns the Java-created binary and JSON files for the supported wire tag. It expects the fixture directory to contain only cross-language-owned hexdumps before generation, which prevents stale Java outputs from mixing with new results. Other generated views, such as hexdumps, remain owned by the matching cross-language tooling.

References: java/…/SyntheticMltGenerator.java• L57-93 java/…/SyntheticMltGenerator.java• L95-225 java/…/SyntheticMltGenerator.java• L284-619 java/…/SyntheticMltUtil.java• L47-56

Build and delivery

Standalone CLI artifacts

The Java build includes mlt-core, mlt-cli, and mlt-tools as separate Gradle modules. The CLI module packages standalone encode and decode jars, so users can run the commands with java -jar without assembling the dependency set themselves.

The CLI depends on the core module for tile conversion and adds support for archive formats, compression, logging, and Kotlin-based command code. The tools module depends on the same core module and exposes a Gradle task for fixture generation rather than a user-facing archive converter.

References: java/settings.gradle• L5-9 java/…/build.gradle• L25-63 java/…/build.gradle• L134-178 java/…/build.gradle• L22-58

Runtime configuration

Environment settings tune batch conversion without changing the command line. They control compression thresholds, progress logging, task queue size, and PMTiles cache size, heap-based limit, block size, and duplicate tracking.

Values with invalid syntax fall back to defaults and produce a warning. Values outside a required range fail a range check instead. A zero tile-log interval means that progress logging does not run, while a zero cache block size disables block alignment. The CLI help presents these settings with the options that use them.

References: java/…/Environment.kt• L3-40 java/…/Environment.kt• L42-100 java/…/EnvironmentResolverTest.kt• L25-179 java/…/EncodeCommandLine.kt• L627-655

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the encode and decode jar main classes aligned with their documented command roles in mlt-cli/build.gradle.
  • Keep accepted input types, output naming, and compression rules aligned between EncodeCommandLine validation and the per-container conversion paths.
  • Keep PMTiles tile-type, compression, and output metadata mappings aligned with the archive reader and writer.
  • Keep PMTiles duplicate-content tracking limits aligned with cache settings and archive write behavior.
  • Keep synthetic fixture cleanup, exact-encoding behavior, and ownership rules aligned with generateSyntheticMlt so stale Java outputs cannot pass the cross-language check.
  • Keep environment variable names, range rules, and help text aligned with the values consumed by batch conversion and PMTiles caching.

Important failure modes

TriggerConsequenceGuard
More than one input mode is suppliedThe encode request is rejected before conversionRequire exactly one input mode
A single output file is used for several individual tilesMultiple tiles would target one pathUse an output directory for multi-file input
PMTiles input is not MVTThe archive cannot enter the MVT-to-MLT pathCheck the archive tile type
PMTiles source compression cannot be mapped to a supported output compressionArchive conversion fails before a valid MLT archive is finalizedUse a supported compression or set an explicit compatible option
A tile cannot be decoded or convertedThe tile is skipped or the batch fails according to the error policyUse comparison checks and choose --continue only for best-effort batches
A shared archive writer receives concurrent writesOutput data can be corruptedSerialize archive writes and wait before finalization
Synthetic output already contains non-owned filesFixture generation can overwrite or mix stale resultsRefuse generation until the fixture directory is clean
An environment value passes parsing but fails its range ruleStartup or conversion configuration fails instead of using a safe valueKeep range checks aligned with the documented variable behavior

Key files

FileWhy to read it
java/…/Encode.ktMain encode lifecycle and user-visible operation selection
java/…/EncodeCommandLine.ktSupported input, output, analysis, compression, and conversion controls
java/…/Conversion.ktShared per-tile conversion and validation path
java/…/MBTiles.ktMBTiles batch conversion and metadata transfer
java/…/OfflineDB.ktOffline database copy-and-update workflow
java/…/PMTiles.ktPMTiles range conversion, caching, compression, and archive output
java/…/Decode.ktStandalone MLT inspection and timing command
java/…/ReadablePmtiles.ktPMTiles metadata and tile-range view used by conversion
java/…/Environment.ktRuntime tuning values and validation rules
java/…/EnvironmentResolverTest.ktGuarantees for environment parsing, defaults, and range checks
java/…/SyntheticMltGenerator.javaSynthetic fixture scope, cleanup contract, and generated case families
java/…/SyntheticMltUtil.javaFixture validation and output contract
java/…/build.gradleStandalone CLI jar tasks and module runtime boundary
java/…/build.gradleSynthetic fixture generation task