# Java not found when executing script that needs Java

**URL:** <https://discuss.elastic.co/t/java-not-found-when-executing-script-that-needs-java/373058>\
**Category:** Logstash\
**Created:** [January 10, 2025, 12:20pm UTC](https://discuss.elastic.co/t/java-not-found-when-executing-script-that-needs-java/373058 "2025-01-10T12:20:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilsen/32/146631_2.png) [@nilsen](https://discuss.elastic.co/u/nilsen)\
**Post date:** [January 10, 2025, 12:20pm UTC](https://discuss.elastic.co/t/java-not-found-when-executing-script-that-needs-java/373058/1 "2025-01-10T12:20:58Z")

</div>

After upgrading to Logstash 8.11.3, our Logstash stopped working because it can no longer execute a script that needs Java. I believe this is caused by Logstash now using it's internally shipped JDK.

**Logstash Exec Input Plugin Configuration**

```auto
exec {
  command => '/ourpath/wildfly/bin/jboss-cli.sh --controller=localhost:9990 --user=admin --password= ******** --connect --command="/subsystem=datasources/data-source=OurDS/statistics=pool:read-resource(include-runtime=true)" --output-json'
  interval => 30
}

```

**Error**

```auto
/ourpath/wildfly/bin/jboss-cli.sh: line 88: exec: java: not found

```

We made Logstash echo JAVA, JAVA\_HOME and other variables to see what it can see, and it looks like it sees nothing.

This did work on our previous Logstash version, which I'm _guessing_ was 8.7.0.

Anyone have any ideas how to fix this?

Potential solutions we have though about:

- Not using the internal Logstash JDK, but this seems like bad practice.
- Manually setting variables for Logstash, such as JAVA, JAVA\_HOME, pointing to our local JDK.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 10, 2025, 2:28pm UTC](https://discuss.elastic.co/t/java-not-found-when-executing-script-that-needs-java/373058/2 "2025-01-10T14:28:42Z")

</div>

If you configure

```
exec { command => "env" schedule => "* * * * *" }
filter {
    mutate { split => { "message" => "
" } }
}

```

you will see that JAVACMD points to the Java executable. This gets configured by /usr/share/logstash/bin/bin/logstash.lib.sh

---

<div class="post-metadata">

**Author:** ![nilsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilsen/32/146631_2.png) [@nilsen](https://discuss.elastic.co/u/nilsen)\
**Post date:** [January 10, 2025, 2:44pm UTC](https://discuss.elastic.co/t/java-not-found-when-executing-script-that-needs-java/373058/3 "2025-01-10T14:44:17Z")

</div>

So would you suggest editing the jboss-cli.sh script to use Logstash's Java executable instead?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 10, 2025, 3:17pm UTC](https://discuss.elastic.co/t/java-not-found-when-executing-script-that-needs-java/373058/4 "2025-01-10T15:17:46Z")

</div>

That's one option. Another would be to create a wrapper that parses the directory from JAVACMD and adds it to PATH. Then invoke the wrapper from the exec input. There are many ways to get what you want.
