# Java execution errors on the test operation of the daml tool when run in a bazel sandbox

**URL:** <https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895>\
**Category:** App Development\
**Tags:** daml-sdk\
**Created:** [February 10, 2022, 5:52pm UTC](https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895 "2022-02-10T17:52:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mesch](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/mesch/32/3248_2.png) [@mesch](https://forum.canton.network/u/mesch)\
**Post date:** [February 10, 2022, 5:52pm UTC](https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895/1 "2022-02-10T17:52:41Z")

</div>

I created bazel build rules for the daml tool operations from the sdk. The sdk is set up hermetically from its tar bal as an external bazel workspace and the tools from the sdk are wired into a bazel toolchain.

When the test rule executes `daml test` during the `bazel test` execution, I see these error messages:

on macos:

```haskell
damlc: ScenarioServiceException "Failed to run java: fd:21:                                                       
hGetContents: invalid argument (invalid byte sequence)"                                                           

```

and on some linux configurations:

```haskell
damlc: ScenarioServiceException "Failed to run java: java:                                                         
readCreateProcessWithExitCode: posix_spawnp:                                                                       
does not exist (No such file or directory)"                                                                        

```

while on other linux configurations the test just works fine. This is all under bazel 5.0.0 with the daml sdk 1.18.1. Directly executing the test executable that bazel creates always works.

I suspect it’s an interaction with the bazel sandbox, but I don’t know where those error messages come from, so I don’t quite understand what exactly is missing or misplaced inside the sandbox.

Do those error messages ring a bell with anyone who could point me to the place they are from?

Thanks a lot!  
mesch.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [February 10, 2022, 8:03pm UTC](https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895/2 "2022-02-10T20:03:15Z")

</div>

If `JAVA_HOME` is set, we use that to locate `java`. If not which seems to be the case here, we just assume it is in PATH. So you need to setup your bazel rules such that JAVA is in path before calling `daml test`.

---

<div class="post-metadata">

**Author:** ![mesch](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/mesch/32/3248_2.png) [@mesch](https://forum.canton.network/u/mesch)\
**Post date:** [February 10, 2022, 9:23pm UTC](https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895/3 "2022-02-10T21:23:38Z")

</div>

Thanks a lot, that already helps!

I now set JAVA\_HOME to point to bazel’s default runtime toolchain. On macos, this changes the error message to

```haskell
damlc: ScenarioServiceException "Failed to run java: external/local_jdk/bin/java:
readCreateProcessWithExitCode: posix_spawnp: failed (Undefined error: 0)"

```

Using another toolchain version, e.g. `--java_runtime_version=remotejdk_11` yields the same error:

```haskell
damlc: ScenarioServiceException "Failed to run java: external/remotejdk11_macos_aarch64/bin/java:
readCreateProcessWithExitCode: posix_spawnp: failed (Undefined error: 0)"

```

Does this ring a bell?

Generally, which JDK version should I use with the DAML SDK?

---

<div class="post-metadata">

**Author:** ![mesch](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/mesch/32/3248_2.png) [@mesch](https://forum.canton.network/u/mesch)\
**Post date:** [February 11, 2022, 5:21am UTC](https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895/4 "2022-02-11T05:21:07Z")

</div>

OK, I found the remaining error: the value of `JAVA_HOME` _must_ be an absolute path. If it’s relative (i.e. what bazel would give you) and valid from the working directory when `damlc` is invoked, it won’t work.

Apparently `damlc` internally either changes its working dir, or resolves a relative value of `JAVA_HOME` against another directly than the current one at invocation time. Perhaps `--project-root`?

Anyway, this is solved for me now.

Cheers,  
mesch.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [February 11, 2022, 5:36am UTC](https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895/5 "2022-02-11T05:36:07Z")

</div>

Yes `--project-root` changes the working directory so that’s where things break.

---

<div class="post-metadata">

**Author:** ![Felix\_Kam](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/felix_kam/32/66_2.png) [@Felix\_Kam](https://forum.canton.network/u/Felix_Kam)\
**Post date:** [April 11, 2022, 2:52am UTC](https://forum.canton.network/t/java-execution-errors-on-the-test-operation-of-the-daml-tool-when-run-in-a-bazel-sandbox/3895/6 "2022-04-11T02:52:07Z")

</div>

I had the same error today and took a while to realise it was because my JAVA\_HOME wasn’t set correctly (found it here actually) 😂

Can the error message be more helpful / indicate that JAVA\_HOME not being set is the obvious thing the user should check ?
