> ## Documentation Index
> Fetch the complete documentation index at: https://flox-daniel-dev-89-update-auto-activate-docs-man-pages.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# JVM

> Common questions and solutions for using the JVM ecosystem with Flox

## Build with Flox

Not only can you *develop* your software with Flox, but you can *build* it as well.
See the [builds](/concepts/builds) concept page for more details.

### Manifest builds

This example will use [Gradle](https://gradle.org/) and the [shadowJar](https://gradleup.com/shadow/) plugin, though a number of build systems exist in the Java ecosystem.
The core of building a Java artifact with Flox looks like this:

* Bundle the application into a JAR
* Place the JAR into `$out/lib/`
* Create a script that calls `java -jar <path to jar>`, where `<path to jar>` is the path to the jar in `$out/lib` at runtime, where `$out` is not set.

```toml theme={null}
[build.myproject]
command = '''
  # Create the destination directories
  mkdir -p "$out"/{lib,bin}
  # Build a fat jar with gradle using the shadowJar plugin
  gradle shadowJar
  # Copy the newly built jars to $out
  cp build/libs/*.jar $out/lib

  # Build a script that gets the absolute path to the JAR at run time
  # and then calls 'java -jar $JAR_PATH'
  echo '#!/usr/bin/env bash' > $out/bin/myproject
  echo 'SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"' >> $out/bin/myproject
  echo 'JAR_PATH="$SCRIPT_DIR/../lib/myproject-app-all.jar"' >> $out/bin/myproject
  echo 'exec java -jar "$JAR_PATH" "$@"' >> $out/bin/myproject

  # Ensure that the script has the correct permissions
  chmod 755 $out/bin/myproject
'''
```

Since `$out` is not set at runtime, the script that calls `java -jar <path to jar>` needs to find the location of the JAR at runtime.
Note that `pwd` will return the location from which the built artifact is run, not the location of the artifact itself, which is why the script goes through the process of setting `SCRIPT_DIR` and `JAR_PATH`.
