# Can I force ES 7+ to use bundled JDK instead of the one in JAVA\_HOME?

**URL:** <https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622>\
**Category:** Elasticsearch\
**Created:** [September 16, 2019, 9:38am UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622 "2019-09-16T09:38:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mesztam](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mesztam](https://discuss.elastic.co/u/mesztam)\
**Post date:** [September 16, 2019, 9:38am UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/1 "2019-09-16T09:38:48Z")

</div>

Hi,

is it possible to force ES to use the bundled JDK instead of the one pointed by JAVA\_HOME?  
In some environments, elder version of JAVA is already installed and used by other applications, and customers may refuse to upgrade it centrally because of ES.  
(Windows / Installed as a service by msi)

thanks,  
Tamas

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 16, 2019, 1:38pm UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/2 "2019-09-16T13:38:10Z")

</div>

Disclaimer: I am no windows expert, so feel free to fully ignore my advice. Under other operating systems, unsetting JAVA\_HOME would work, and checking the scripts under the `bin` directory in Elasticsearch the behaviour for windows seems to be the same.

---

<div class="post-metadata">

**Author:** ![mesztam](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mesztam](https://discuss.elastic.co/u/mesztam)\
**Post date:** [September 17, 2019, 9:39am UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/3 "2019-09-17T09:39:27Z")

</div>

In Windows, the elasticsearch.exe is started as a service, but it seems that it does not call elasticsearch-env.bat during this, that would set up the paths. It seems to always prefer JAVA\_HOME coming from the process user, that is LocalSystem by default. And this is the problem, because in this case, I should remove the JAVA\_HOME on system level (that is not acceptable) or always create a dedicated user for ES service (and set JAVA\_HOME on user level) =\> overhead in most cases. The simplest solution would be adding a config file to elasticsearch.exe, and letting you configure a custom java path there, that would be checked first.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [September 18, 2019, 12:22am UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/4 "2019-09-18T00:22:28Z")

</div>

Hey @mesztam, it sounds like you're using the Windows MSI installer, based on the installation of an `elasticsearch.exe`. The installer is configured to use the bundled JDK from version 7.3.0 onwards.

Prior 7.x versions of the installer require `JAVA_HOME` to be set at installation time, or for a version of Java to be detected in the registry. In these versions, it is possible to have `elasticsearch.exe` use the bundled JDK by

1. Installing Elasticsearch with the MSI, but not installing as a Windows service

2. updating `JAVA_HOME` to point to the location of the bundled JDK

3. Registering `elasticsearch.exe` as a Windows service with

4. Starting the service with PowerShell

---

<div class="post-metadata">

**Author:** ![mesztam](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mesztam](https://discuss.elastic.co/u/mesztam)\
**Post date:** [September 18, 2019, 10:03am UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/5 "2019-09-18T10:03:05Z")

</div>

Hi, right, I installed with the MSI v 7.3.1. Still, if I start the service, it is not using the bundled JDK, but the one it finds in my system (JAVA\_HOME and Path):

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b897fdfa69d23f6c4dd674b381b0145e2edada92.png)

Maybe it would fall back to the bundled JDK, if I would remove adoptopenjdk from path/java\_home, but in a prod environment where potentially other software using java are also installed, this cannot be done.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [September 18, 2019, 1:31pm UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/6 "2019-09-18T13:31:55Z")

</div>

> [@mesztam](#):
>
> it finds in my system (JAVA\_HOME and Path)

It's intended to work like this; if `JAVA_HOME` environment variable it set, it will use that, and if it is not set, it will use the bundled JDK. This is to allow a user to override using the bundled JDK by explicitly setting `JAVA_HOME`.

---

<div class="post-metadata">

**Author:** ![mesztam](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mesztam](https://discuss.elastic.co/u/mesztam)\
**Post date:** [September 18, 2019, 1:56pm UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/7 "2019-09-18T13:56:42Z")

</div>

Hi,

I understand that, but in windows environment, if you run it as a service, you cannot override the JAVA\_HOME only for the service. I can delete it only on system-level, making all other JAVA applications non-working. I can imagine that in linux environment, you can clear the java\_home for this specific process on startup in a shell script or so, but in windows, you cannot do this for a windows service.

In many environments, JAVA is already installed and other java apps are running on the server, thus JAVA\_HOME is set to some java folder (maybe even 32 bit or old), but if this JAVA version is not sufficient for ES, then I have no choice but 1) upgrading the system-installed JAVA to a newer one, risking that I make other java apps non-working. OR I remove JAVA\_HOME (to let ES fall back to the bundled JDK), but then again, all other JAVA apps will stop working. Do you see what I mean?

I think, if you already bundle ES with JDK, the default should be using the bundled JDK. And using another one only on demand (e.g. if you delete the jdk folder, then it could fall back to JAVA\_HOME). Or even simpler would be checking for some specific dedicated env. variable, like "ES\_JAVA\_HOME", and if it set, then use it, and try all the other options only after this.

regards,  
Tamas

---

<div class="post-metadata">

**Author:** ![scottdfedorov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/scottdfedorov/32/64699_2.png) [@scottdfedorov](https://discuss.elastic.co/u/scottdfedorov)\
**Post date:** [September 24, 2019, 3:44pm UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/8 "2019-09-24T15:44:07Z")

</div>

> [@mesztam](#):
>
> I think, if you already bundle ES with JDK, the default should be using the bundled JDK. And using another one only on demand (e.g. if you delete the jdk folder, then it could fall back to JAVA\_HOME). Or even simpler would be checking for some specific dedicated env. variable, like "ES\_JAVA\_HOME", and if it set, then use it, and try all the other options only after this.
> 
> regards,

**BUMP**  
We are running into the same situation. We have JAVA\_HOME set for our system, it's using 1.7, which doesn't work, but is required for other things installed on this computer.

Is there no way to force Elasticsearch to use the bundled JDK? As mentioned, perhaps by a different environment variable or some other configuration options?

Thanks

---

<div class="post-metadata">

**Author:** ![mesztam](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mesztam](https://discuss.elastic.co/u/mesztam)\
**Post date:** [September 25, 2019, 4:42am UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/9 "2019-09-25T04:42:38Z")

</div>

Just an extension: this is already a problem during the installation (via msi), because the installer already does some jobs (e.g. plugin install) via java. And if you have an incompatible JAVA version on your system, then the installer already crashes because of this.

---

<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:** [October 23, 2019, 4:44am UTC](https://discuss.elastic.co/t/can-i-force-es-7-to-use-bundled-jdk-instead-of-the-one-in-java-home/199622/10 "2019-10-23T04:44:13Z")

</div>

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