I am using a jenkins slave with Java version 7 which is used to deploy application.
Now have to use Java 17 and also Java 7 on same slave machine. How can we run two Java versions for deploying application with different versions?
I can dot his by adding one more slave in jenkins with Java 17, but I am searching if I can do this by same slave.
How we do this at our company is by using the "JDK installations" configuration in Jenkins. That is found in Jenkins > Manage Jenkins > Tools and you can add various JDK tools to Jenkins and then you can use those in your pipelines like outlined here: https://stackoverflow.com/a/48368506/21960203
In general I've found this to be the best way to handle when you need to have multiple versions of Java for different projects.