# Using different Java versions for agents and jobs

**URL:** <https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [February 13, 2024, 3:58pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443 "2024-02-13T15:58:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flakky](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/flakky/32/7031_2.png) [@Flakky](https://community.jenkins.io/u/Flakky)\
**Post date:** [February 13, 2024, 3:58pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/1 "2024-02-13T15:58:42Z")

</div>

Hi!

I have a Jenkins setup in my Kubernetes cluster, but my agents are outside. I connect agents using SSH, but I have one problem with Java.

For my project I must use java 8, however new Jenkins only supports 11 and 17. So in order to launch my node agent and connect, I must remove environment variable from the node settings, start my node, and then add JAVA\_HOME jdk1.8.0\_151 back to node environment variables. This is very inconvenient, since I have to manually do these steps if Jenkins or the agent get restarted.

I know I could add jdk1.8.0\_151 environment variable to my job, but I think this is not very correct way, since I might have several nodes with different path to java8.

So, what may be the correct approach here?

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [February 13, 2024, 4:11pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/2 "2024-02-13T16:11:48Z")

</div>

You can configure the full path to java in the config (under advanced settings). This way you avoid that JAVA\_HOME is used or java is taken from the path.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/c/c70b51112b1b6f226a5166f4a83d12604fb56ea3.png)

---

<div class="post-metadata">

**Author:** ![Flakky](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/flakky/32/7031_2.png) [@Flakky](https://community.jenkins.io/u/Flakky)\
**Post date:** [February 14, 2024, 3:39pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/3 "2024-02-14T15:39:12Z")

</div>

Thank you! I didn’t notice this field. It looks like the agent starts fine even with the env variable now.

---

<div class="post-metadata">

**Author:** ![Dhruva](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/dhruva/32/6803_2.png) [@Dhruva](https://community.jenkins.io/u/Dhruva)\
**Post date:** [January 29, 2025, 11:10am UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/4 "2025-01-29T11:10:18Z")

</div>

@mawinter69 , our jenkins server running on Java 17, and agents on java 8, added java path in agents advanced settings, getting  
Verified agent jar. No update is necessary.  
Expanded the channel window size to 4MB  
[01/29/25 16:32:48] [SSH] Starting agent process: cd “/var/lib/Jenkins” && /usr/java/jdk1.8.0\_321-amd64/bin/java -jar remoting.jar -workDir /var/lib/Jenkins -jar-cache /var/lib/Jenkins/remoting/jarCache  
Error: A JNI error has occurred, please check your installation and try again  
Exception in thread “main” java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0  
at java.lang.ClassLoader.defineClass1(Native Method)

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 29, 2025, 12:01pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/5 "2025-01-29T12:01:42Z")

</div>

The agent process must run with Java 11 or Java 17 (depends on what version of Jenkins you’re using).  
But this should not stop you from having multiple Java versions installed on the agent and use whatever java version you need for the build.

---

<div class="post-metadata">

**Author:** ![Dhruva](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/dhruva/32/6803_2.png) [@Dhruva](https://community.jenkins.io/u/Dhruva)\
**Post date:** [January 29, 2025, 12:12pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/6 "2025-01-29T12:12:04Z")

</div>

@mawinter69 , our source code still using java 8

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 29, 2025, 12:21pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/7 "2025-01-29T12:21:32Z")

</div>

Then use java8 to build your sources but the agent process must run a newer java version.  
It would help if you tell us how you’re building your sources. When you use the Maven job type then it is strongly advised to move away from it.

---

<div class="post-metadata">

**Author:** ![Dhruva](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/dhruva/32/6803_2.png) [@Dhruva](https://community.jenkins.io/u/Dhruva)\
**Post date:** [January 29, 2025, 12:33pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/8 "2025-01-29T12:33:00Z")

</div>

we are using gradle for build our jars

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 29, 2025, 12:37pm UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/9 "2025-01-29T12:37:06Z")

</div>

So where is the problem?  
Not familiar with gradle but you run this is a separate process I assume. Does it rely on `JAVA_HOME` being set? Then set JAVA\_HOME to the jdk you need.

---

<div class="post-metadata">

**Author:** ![DivyaS](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/divyas/32/19995_2.png) [@DivyaS](https://community.jenkins.io/u/DivyaS)\
**Post date:** [February 27, 2026, 11:16am UTC](https://community.jenkins.io/t/using-different-java-versions-for-agents-and-jobs/12443/10 "2026-02-27T11:16:13Z")

</div>

were you able to fix this issue? I am facing same issue
