I'm trying to build a jar
file that includes the MySQL driver
for JDBC
. So far I have a very basic build.gradle
file that is using the shadowJar
plugin to help build this jar
file.
The problem is, when running anything Gradle related, I receive this error:
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/jdk-11.0.1/bin/java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
When trying to locate Java with $ which java
I get
/usr/bin/java
and with $ ls -la /usr/bin | grep -i javaj
I receive
lrwxrwxrwx 1 root root 22 Sep 21 11:32 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 29 Nov 5 21:12 java2groovy -> /etc/alternatives/java2groovy
lrwxrwxrwx 1 root root 23 Nov 5 20:33 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 25 Nov 5 20:33 javadoc -> /etc/alternatives/javadoc
lrwxrwxrwx 1 root root 23 Nov 5 20:33 javah -> /etc/alternatives/javah
lrwxrwxrwx 1 root root 23 Nov 5 20:33 javap -> /etc/alternatives/javap
So far none of this information has been helpful for me but I'm leaving it here just in case.
Also, when I use $ readlink -f $(which java)
I receive:
/usr/lib/jvm/jdk-11.0.1/bin/java
Which to me seems like it is the appropriate path that Gradle is trying to look.
Lastly, in my .bashrc
I have put this in the file to set my JAVA_HOME
:
## JAVA ##
export JAVA_HOME="/usr/lib/jvm/jdk-11.0.1/bin/java"
export PATH=$PATH:/usr/lib/jvm/jdk-11.0.1/bin
Any ideas on why running $ ./gradlew shadowJar
would not be able to find Java?
Edit
According to this question which seems similar to my question, my version of Gradle is trying to set its own JAVA_HOME
path which I've figured out it is being set to /usr/bin/java/bin/java
which does not exist.