# Command reference

The npm package `java-npm-cli` installs the `jpm` command. Use `jpm --help` and `jpm --version` to inspect the installed CLI. Node 22+ is required. Windows support starts with 0.1.0-alpha.2.

## Command overview

Run dependency, development and build commands from the project directory containing `package.json`. Maven runs through the generated `mvnw` (macOS/Linux) or `mvnw.cmd` (Windows).

| Command | What it does |
| --- | --- |
| `jpm` | Open the interactive menu. With redirected input or output, print help. |
| `jpm help`, `jpm --help`, `jpm -h` | Show CLI help. |
| `jpm --version`, `jpm -v` | Print the installed jpm version. |
| `jpm create [name]` | Create a Spring MVC project. Use `jpm create hello-jpm --java 21 -y` to skip the wizard. |
| `jpm install` | Sync the POM and ask Maven to fetch project dependencies and plugins. |
| `jpm add <group:artifact[@version]> [--scope <scope>] [--optional]` | Declare a Maven dependency, sync the POM and resolve dependencies. |
| `jpm remove <group:artifact>` | Remove a direct dependency from the manifest and POM. |
| `jpm list [--json]` | List direct dependencies declared in `package.json`. |
| `jpm tree` | Show Maven’s resolved dependency tree, including transitive dependencies. |
| `jpm sync` | Regenerate `pom.xml` from `package.json`. |
| `jpm dev` | Start Spring Boot and restart it after saved changes compile. |
| `jpm test` | Run the Maven test phase. |
| `jpm build` | Run tests and package an executable JAR in `target/`. |
| `jpm run <task>` | Alias for `jpm dev`, `jpm test` or `jpm build`. |
| `jpm doctor [--json]` | Check the project, JDK, wrapper and POM. Print repair suggestions. |
| `jpm jdk`, `jpm jdk list [major]` | List installed JDKs and mark the selected one. |
| `jpm jdk list [major] --remote` | List available Temurin releases for this platform. `-r` is short for `--remote`. |
| `jpm jdk install [major]`, `jpm jdk i [major]` | Install or reuse a cached Temurin JDK. The current selection stays in effect. |
| `jpm jdk use <major> [--global]` | Select a JDK, downloading Temurin if needed. `--global` sets the user default. |
| `jpm jdk env [major]` | Print shell commands to set `JAVA_HOME` and `PATH`. |

For Maven arguments, put `--` after the command, as in `jpm test -- -Dtest=JpmHelloTests`. See [project creation options](#create-a-project), [dependency scopes](#dependencies-and-pom), [JDK selection](#jdk-management) and the [PowerShell quick start](#windows-powershell).

## Interactive terminal

### `jpm`

Run `jpm` without arguments to open the welcome menu. Outside a valid jpm project, it offers project creation, the command guide, and exit. In a valid project, it also offers development, tests, and diagnostics. Use the arrow keys to move and Enter to select; an action starts only after selection.

The welcome page, creation wizard, and doctor use a single-column layout. The header pairs `; jpm` with the version in the terminal’s normal foreground. A blue arrow marks the selected action. Menus show as many choices as the available rows permit and hide the header when space is tight.

Interactive prompts require both input and output to be terminals. Pipes, redirected output, CI, and `TERM=dumb` use plain output without menus or cursor movement. Bare `jpm` shows help in those environments. `NO_COLOR=1` disables colors while retaining terminal interaction. `--help`, `--version`, `--json`, and `jdk env` do not gain a banner or interactive menu.

### `jpm help`

Print the command guide with `jpm help`, `jpm --help` or `jpm -h`.

### `jpm --version`

Print the installed CLI version. The short form is `jpm -v`.

## Create a project

### `jpm create`

```sh
jpm create my-app --java 21 -y
```

| Option | Meaning |
| --- | --- |
| `<name>` | Lowercase kebab-case directory/artifact name |
| `--java <major>` | Java target; otherwise configured default, then 21 |
| `--boot <version>` | Exact version currently offered by Initializr |
| `--group <groupId>` | Java group, default `com.example` |
| `--package-name <package>` | Explicit Java package; otherwise derived from group/name |
| `--template spring` | The only supported template: Spring MVC |
| `--initializr <url>` | Override the Spring Initializr endpoint (https required); defaults to `JPM_INITIALIZR_URL`, then `start.spring.io` |
| `-y`, `--yes` | Skip interactive questions; provide a project name |

In an interactive terminal, missing name/Java choices are prompted. The Java selector offers the configured default, detected installed versions, and entry of another major version. Selecting a version does not install it; Spring Initializr still validates the requested Java target. Use `-y` and a project name to skip the wizard, including in a terminal.

Creation fetches a Maven template from the configured Spring Initializr endpoint and adds a JSON manifest, `.jpmrc`, hello endpoint, and HTTP test. It refuses an existing destination. It does not install dependencies, install a JDK, or start a server. Completion output lists the next commands only after the project is created.

## Dependencies and POM

### `jpm add`

```sh
jpm add org.springframework.boot:spring-boot-starter-validation
jpm add org.assertj:assertj-core --scope test
jpm add org.apache.commons:commons-lang3@3.20.0
jpm add com.google.guava:guava
```

Use `group:artifact[@version]`, optionally followed by `--scope` (`compile`, `runtime`, `provided` or `test`) and `--optional`. jpm records the dependency, syncs the POM and runs Maven. Without `@version`, jpm keeps the version Spring Boot manages; for any other library it saves the latest stable release from Maven Central, like npm saving the current version. Set `JPM_MAVEN_REPOSITORY` to look up versions in a trusted mirror instead. A preflight error, including an unknown coordinate, leaves the files unchanged. If Maven fails after the files are saved, fix the coordinate or network issue and retry with `jpm install`.

### `jpm install`

`jpm i` is an alias. As with `npm install <package>`, `jpm install <group:artifact>` adds that dependency. Run `jpm install` in the project directory to synchronize the POM and fetch Java dependencies and plugins through Maven’s `dependency:go-offline` goal.

### `jpm list`

Run `jpm list` for the project’s direct declarations or `jpm list --json` for structured output. Both work without a JDK or network connection. An omitted version requests Spring Boot dependency management. Use `jpm tree` to see the actual resolved version.

### `jpm remove`

`jpm remove org.apache.commons:commons-lang3` removes the coordinate from the project manifest and POM without invoking Maven.

### `jpm sync`

After editing `package.json`, run `jpm sync` to regenerate the POM. jpm checks for manual POM edits before writing.

### `jpm tree`

```sh
jpm tree
jpm tree -- '-Dincludes=org.apache.commons:*'
```

Maven displays resolved direct and transitive dependencies. This requires a usable JDK and Maven Wrapper and may download artifacts.

## Development, tests, and builds

### `jpm dev`

```sh
jpm dev
jpm dev -- -Dspring-boot.run.arguments=--server.port=8081
```

Dev mode requires the Boot DevTools dependency. It watches Java and resource files under `src/main`, serializes compilation, and triggers a restart after successful compilation. Deleted or renamed files cause stale outputs to be cleaned. Fix a compilation error and save again to retry. Restart jpm after dependency, JDK or build-configuration changes. Ctrl+C stops the app and Maven.

### `jpm test`

Run `jpm test` for all Java tests. To select the generated HTTP test, run `jpm test -- -Dtest=JpmHelloTests`. Arguments after `--` go to Maven, including `--help`.

### `jpm build`

Run `jpm build` to invoke Maven’s package phase, run tests and write the executable JAR to `target/`. Use `jpm build -- -DskipTests` to skip test execution.

### `jpm run`

`jpm run dev`, `jpm run test` and `jpm run build` call the corresponding jpm command. These are the three supported task names.

## JDK management

### `jpm jdk`

`jdk` lists installed JDKs, with the installation selected for jpm first. The current row has a blue accent and a `*` / `(current)` label, followed by the configuration source. This is jpm's selection, which may differ from the shell's `java`. Listing does not change it.

### `jpm jdk list`

`jdk list` is an alias for `jdk`. Both detect installations and verify `java` and `javac`, without network access. `jdk list <major>` filters this local list; a current installation outside the filter is not shown. With no configuration, they list installations without marking one current. Invalid configuration or an unavailable selected JDK produces an error after displaying the installed versions.

`jdk list --remote` (or `-r`) queries Temurin releases for the current operating system and CPU. It shows the latest available GA release for each supported major version; `jdk list 21 -r` shows the available Java 21 patch/build history. Only JDKs are listed, not JREs or early-access builds. Installed/current labels require a matching detected Temurin runtime version. Remote listing fetches metadata only: it does not download JDK archives or change the selection.

### `jpm jdk install`

`jpm jdk install 21` (or `jpm jdk i 21`) installs a Temurin JDK to `~/.jpm/jdks/<major>` and verifies size/checksum. It reuses an existing complete cached installation, without upgrading it or changing the selection. Omitting the version requires an existing selection. Windows uses the matching Adoptium ZIP when a build is available for the selected architecture.

### `jpm jdk use`

`jpm jdk use <major> [--global]` reuses a usable local JDK of that major version, regardless of distribution. If none is found, it installs Temurin. It checks project target compatibility before downloading and saves the choice in project/user `.jpmrc` only after successful preparation; a failed download leaves the previous choice intact. `--global` saves the user default without imposing the current project's target. Neither form changes the project's compilation target.

### `jpm jdk env`

`jpm jdk env [major]` prints quoted bash/zsh exports on macOS/Linux or PowerShell assignments on Windows. It does not edit shell startup files; review the output before evaluating it. For example, in bash or zsh, run `eval "$(jpm jdk env)"` to apply the selection to the current terminal.

Version arguments are major versions from 17 to 99. New downloads select the latest available Temurin release for that major. Although remote listing displays full patch/build versions, installing or pinning an exact build and selecting another distribution are not supported yet. There are no `--distribution`, `--all`, or `--versions` flags; use a positional major version and `--remote` to choose the listing scope.

See [JDK configuration](https://coderserio.github.io/java-npm/docs/configuration/#jdk-selection) for precedence and project boundaries.

## Diagnostics and exit status

### `jpm doctor`

```sh
jpm doctor
jpm doctor --json
```

`doctor` checks Node/platform, JSON, JDK selection, target compatibility, shell environment, Maven Wrapper, and POM state. It executes local Java version probes, but does not call Maven, access the network, install tools, or change files. Outside a project it checks only the environment and reports the missing project as a warning.

In a terminal, doctor shows an environment summary followed by labeled check results and repair suggestions. Warnings and errors remain visible even when colors are disabled. Redirected output keeps the plain checklist, and `doctor --json` always emits only the JSON report.

JSON output has `ok` and `checks`; each check includes `name`, `status` (`ok`, `warn`, `error`), `detail`, and an optional `action`. Any error produces exit 1; warnings alone do not. Maven commands propagate failure status; signal exits use conventional codes such as 130 for SIGINT and 143 for SIGTERM.

## Windows PowerShell

Install Node.js 22 or newer. Install jpm with `npm.cmd install -g java-npm-cli`. Use `jpm.cmd` if your PowerShell policy blocks the npm-generated .ps1 shim.

```powershell
jpm.cmd create hello-jpm --java 21 -y
cd hello-jpm
jpm.cmd jdk use 21
jpm.cmd dev
# After stopping the app with Ctrl+C
jpm.cmd test
jpm.cmd build
```

jpm selects the JDK for its Maven children automatically. To select it for this PowerShell session as well, review `jpm.cmd jdk env` and run `(jpm.cmd jdk env) -join [Environment]::NewLine | Invoke-Expression`.
Windows uses the generated `mvnw.cmd`. Spaces in project paths and Maven argument values are supported. Use a project path without quotes, percent or exclamation marks. Arguments containing cmd control characters are rejected.
