summaryrefslogtreecommitdiff
path: root/modules/templates/java/README.md
blob: 7cc573515377bcf7ed9431fcee8a681b62f133b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Java Development Environment

A simple Nix Flake providing a reproducible Java development environment.

## Included Tools

* **JDK 21** – Java compiler and runtime
* **Maven** – Dependency management and project build tool
* **Gradle** – Alternative build system
* **JDT Language Server** – Language server used by many editors (Neovim, VS Code, Helix, etc.)

## Usage

Enter the development shell:

```bash
nix develop
```

When the shell starts, it will display the installed Java version and create an `out/` directory for compiled classes if it doesn't already exist.

## Helper Commands

The shell provides a few convenience aliases for small Java projects.

### `jbuild`

Compiles every Java source file under `src/` into the `out/` directory.

```bash
jbuild
```

Equivalent to:

```bash
find src -name "*.java" | xargs javac -d out
```

---

### `jrun`

Builds the project and runs:

```text
src.Main
```

```bash
jrun
```

This assumes your application's entry point is `src.Main`.

---

### `jclean`

Removes compiled output.

```bash
jclean
```

## Project Layout

This template assumes a simple project structure:

```text
.
├── flake.nix
├── src/
│   └── Main.java
└── out/
```

For larger projects, consider using Maven or Gradle instead of the helper aliases.

## Customization

This template is intended as a starting point. You can easily modify it to:

* use a different JDK version
* add testing frameworks (JUnit, TestNG)
* include formatting and linting tools
* add debugging utilities
* add database or web development dependencies

Because everything is defined in the flake, the development environment remains reproducible across Linux, macOS, and other supported platforms.