0

I want to write a batch file to trigger the gradlew shadowJar file from my machine. Currently i have two java versions in my machine, java8 and java17. My environment variable JAVA_HOME is set to Java8. But to execute the gradle i need java 11 (its requirement). By writing a new custom batch file, i will set the JAVA_HOME for Java11.

I tried to write a batch file but its not working,

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:/Program Files/Java/jdk-17
set PATH=C:/Program Files/Java/jdk-17/bin;
set APP_HOME=APPDIR
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
"%JAVA_EXE%" %DEFAULT_JVM_OPTS%  -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

When i execute the above batch file, it's failing and its not working as expected. How can i log the execution error?

User51
  • 887
  • 8
  • 17
Zia
  • 1,001
  • 1
  • 13
  • 25
  • Please do not do this ```set PATH=C:/Program Files/Java/jdk-17/bin;```. If you must modify the content of `PATH`, please just add to it, do not delete everything from it except for your wanted location. Like this: ```Set "PATH=%ProgramFiles%\Java\jdk-17\bin;%PATH%"```. You also need to change ```set JAVA_HOME=C:/Program Files/Java/jdk-17``` and ```set JAVA_EXE=%JAVA_HOME%/bin/java.exe``` to ```Set "JAVA_HOME=%ProgramFiles%\Java\jdk-17"``` and ```Set "JAVA_EXE=%JAVA_HOME%\bin\java.exe"``` respectively. Windows directories use backward slash separators, not forward slashes, like in Unix. – Compo Jan 27 '23 at 11:33
  • If your primary ask is "How do I tell Gradle to use a specific JDK version?", you could look here: https://stackoverflow.com/questions/18487406/how-do-i-tell-gradle-to-use-specific-jdk-version Esp if the requirement is defined by the project, this might be useful. Notably, a batch file like what you're constructing above may not be the best approach to accomplish this. If you did want to stick with this approach, you could just set the `JAVA_HOME` var, and then just do `CALL gradlew ...` – User51 Jan 27 '23 at 14:52

0 Answers0