# Custom JDK for Logstash

**URL:** https://discuss.elastic.co/t/custom-jdk-for-logstash/124422
**Category:** Logstash
**Created:** [March 17, 2018, 10:23pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422 "2018-03-17T22:23:25Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://discuss.elastic.co/u/qube)
#### Post date: [March 17, 2018, 10:23pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/1 "2018-03-17T22:23:25Z")

</div>

Hello!

According to [this](https://stackoverflow.com/a/6571736) answer, I extracted the exe file (I'm windows user) and copied the necessary files. For Elasticsearch, it worked. I set java\_home variable in the elasticsearch.bat

set JAVA\_HOME=path/to/jdk/file

I tried the same with Logstash. I set the same JAVA\_HOME in logstash.bat file and setup.bat, but no it doesn't work with this way.

How to set JAVA\_HOME for Logstash without installing Java 8 on the PC?

---

<div class="post-metadata">

### Author: ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://discuss.elastic.co/u/qube)
#### Post date: [March 19, 2018, 1:58pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/2 "2018-03-19T13:58:32Z")

</div>

Anyone interested around? Please.

I cannot figure out how to run Logstash with a custom java.exe, but it works with Elasticsearch. What else should I try?

---

<div class="post-metadata">

### Author: ![Magnus\_Kessler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnus_kessler/32/42001_2.png) [@Magnus\_Kessler](https://discuss.elastic.co/u/Magnus_Kessler)
#### Post date: [March 19, 2018, 2:14pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/3 "2018-03-19T14:14:22Z")

</div>

This snippet from `setup.bat` in the logstash `bin` directory suggests that you'd need to provide the path to the JDK top-level directory.

```auto
if defined JAVA_HOME (
  set JAVA="%JAVA_HOME%\bin\java.exe"
)

```

You'll have to point to a copy of the JDK extracted to some location on the file system.

---

<div class="post-metadata">

### Author: ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://discuss.elastic.co/u/qube)
#### Post date: [March 19, 2018, 2:35pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/4 "2018-03-19T14:35:50Z")

</div>

Hello Magnus,  
Thank you for your reply.

Yes, I am trying to set my custom JAVA\_HOME in `logstash.bat` file like:

```
@echo off
setlocal enabledelayedexpansion
set params='%*'
set JAVA_HOME=path\to\custom_jdk_folder\jdk_8u161
...

```

But I think logstash still works with the JAVA\_HOME that it's defined in the System environment variables (It's Windows, yes). Because it prints out as error that `Error: Could not find or load main class Files\Java\jre7\lib\ext\QTJava.zip;` and the error goes on... `C:\Program Files\Java\jre7` is the JAVA\_HOME from the System variables.

Instead of that, I need to run Logstash with the Java here: `path\to\custom_jdk_folder\jdk_8u161`

What am I missing here?

---

<div class="post-metadata">

### Author: ![Magnus\_Kessler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnus_kessler/32/42001_2.png) [@Magnus\_Kessler](https://discuss.elastic.co/u/Magnus_Kessler)
#### Post date: [March 19, 2018, 2:51pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/5 "2018-03-19T14:51:05Z")

</div>

What happens if you set a custom `JAVA_HOME` environment variable (rather than trying to edit the `logstash.bat` file)? Also, is there any reason not to simply install JDK8 system wide on this system?

---

<div class="post-metadata">

### Author: ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://discuss.elastic.co/u/qube)
#### Post date: [March 19, 2018, 2:56pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/6 "2018-03-19T14:56:41Z")

</div>

🙂

I don't have admin rights on the PC, so I cannot set new System environment variable and also install JDK8. I have JDK7 installed and JAVA\_HOME system variable for JDK7.

So, using java.exe from a JDK extracted folder is the only option for me, I guess.

What do you think?

---

<div class="post-metadata">

### Author: ![Magnus\_Kessler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnus_kessler/32/42001_2.png) [@Magnus\_Kessler](https://discuss.elastic.co/u/Magnus_Kessler)
#### Post date: [March 19, 2018, 3:16pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/7 "2018-03-19T15:16:31Z")

</div>

From my reading of the batch files, the `JAVA_HOME` seems to be mainly used to derive the `JAVA` variable. Try if directly setting `JAVA` to the full path to `java.exe` in your modified `logstash.bat` works:

```auto
set JAVA=\path\to\bin\java.exe

```

---

<div class="post-metadata">

### Author: ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://discuss.elastic.co/u/qube)
#### Post date: [March 20, 2018, 6:07am UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/8 "2018-03-20T06:07:24Z")

</div>

No. It didn't work out Magnus. ☹

I tried many other things.. With double quotes, without double quotes, set JAVA\_HOME in `logstash.bat`, set JAVA directly to the java.exe in `setup.bat`, mix them, change them, try other combinations etc but no. None of them works like in the Elasticsearch. I just set my custom JAVA\_HOME in `elasticsearch.bat` and voiala, it just works!

It seems like Logstash never detect my JAVA\_HOME, JAVA variable at all. I want to force it to use my Java8, not the Java7 installed on the PC.

---

<div class="post-metadata">

### Author: ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://discuss.elastic.co/u/qube)
#### Post date: [March 20, 2018, 1:04pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/9 "2018-03-20T13:04:43Z")

</div>

I'm still trying this and up to now no lock ☹

Please someone help me about this to configure with my custom JDK8 package.

---

<div class="post-metadata">

### Author: ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://discuss.elastic.co/u/qube)
#### Post date: [March 20, 2018, 2:52pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/10 "2018-03-20T14:52:49Z")

</div>

OHH!! It works!

If anyone interested, in `logstash.bat` file:  
`set JAVA_HOME=path\to\custom_jdk_folder\jdk_8u161`  
`set CLASSPATH=%JAVA_HOME%\bin`

It's working with these two settings. But I'm not sure if I should add `set PATH=%JAVA_HOME%\bin;%PATH%` also.. But it's working..

Thanks everyone!

---

<div class="post-metadata">

### Author: ![elvarb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elvarb/32/44840_2.png) [@elvarb](https://discuss.elastic.co/u/elvarb)
#### Post date: [March 20, 2018, 3:01pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/11 "2018-03-20T15:01:49Z")

</div>

Simplify this, instead of modifying the original logstash.bat file add another logstash.bat file in a different folder, add JAVA\_HOME at the start of that bat file, then call the real logstash.bat file. That way you can switch between logstash and java versions easily by just modifying your custom logstash.bat file

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 17, 2018, 3:01pm UTC](https://discuss.elastic.co/t/custom-jdk-for-logstash/124422/12 "2018-04-17T15:01:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
