Custom JDK for Logstash

Hello!

According to this 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?

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?

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.

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.

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?

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?

:slight_smile:

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?

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:

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

No. It didn't work out Magnus. :frowning:

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.

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

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

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!

1 Like

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

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