Jenkins: Your JAVA_HOME is invalid on OS X - java

I am using Jenkins to build an android project on a mac stadium VM.
When I VNC into the VM, I can build the project just fine. Java is installed at /usr/bin/java, and my $PATH includes /usr/bin.
When I run the same commands from the Jenkins job, it fails with
ERROR: JAVA_HOME is set to an invalid directory: /var/lib/jenkins/jdk1.8.0_25
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
/var/lib/jenkins/jdk... does not exist on the VM. I have also tried updating the build job to include export JAVA_HOME=/usr/bin, but then I get a different error:
Error: Failed to run "java -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: /usr/bin
All of the other steps seem to work so I can tell that the code is being downloaded to the workspace and everything else is installed properly, and as I said I can build android on the VM from the command line directly.
What can I do to get Jenkins to build on the VM?

The best way to set the JAVA_HOME on a mac is to use java_home after downloading and installing the required JDK from oracle:
export JAVA_HOME=`/usr/libexec/java_home`
If you want Jenkins to use an older version of the JDK ensure use the -v flag:
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
To preview the location just type the java_home command into a Terminal:
$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

Related

Why is cordova picking up the wrong JDK version?

On macOS, when running the terminal command
cordova build android
I get an error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/arnas/Android/Sdk (recommended setting)
ANDROID_HOME=/Users/arnas/Android/Sdk (DEPRECATED)
Requirements check failed for JDK 1.8.x! Detected version: 15.0.2
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.
although running java -version returns java version "1.8.0_291"
My bash_profile settings are:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export ANDROID_HOME=$HOME/Android/Sdk
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
What could be wrong here?
Use the command which java in order to understand the path of your java version 1.8 and then set JAVA_HOME with that path removing the bin/java.
That is:
which java
/usr/bin/java1.8/bin/java
and then replace in your bash_profile your current 'export JAVA_HOME...' with
export JAVA_HOME=/usr/bin/java1.8
What worked for me, was actually setting JAVA_HOME manually in the bash_profile by running nano ~/.bash_profile and entering the line:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home"
I obtained the file path by finding the latest JDK version in the JavaVirtualMachines directory.

Maven "JAVA_HOME should point to a JDK not a JRE"

I had the following command working fine with OpenJDK
mvn clean install
I then uninstalled OpenJDK and installed Oracle JDK 8, and now when I run mvn clean install
The JAVA_HOME environment variable is not defined correctly This
environment variable is needed to run this program NB: JAVA_HOME
should point to a JDK not a JRE
I'm running Linux Mint 19, I did run into a few Stackoverflow questions related to the issue. Most where related to Windows and some that were related to Linux. The Linux ones recommended to run
sudo update-alternatives --config java
but in my case I get
There is only one alternative in link group java (providing
/usr/bin/java): /usr/lib/jvm/java-8-oracle/jre/bin/java Nothing to
configure.
Any idea how I can make mvn clean install work again?
May be java path configuration missing. You can follow this steps:
Create or export JAVA_HOME="JDK directory" . Ex. "C:\Program Files\Java\jdk1.8.0_65"
Create or export Path variable for PATH="JDK Bin DIrectory" . Ex. "C:\Program Files\Java\jdk1.8.0_65\bin"
Run command java -version from your terminal.Check it is correct or not.
Then configure maven. follow these steps :
You can try to install maven globaly. you can skip these steps if already configured.just for check run mvn --version command for checking maven is installed correctly.
Download maven from maven download link
Create or export M2_HOME="MAVEN ROOT LOCATION". Ex. : E:\SoftwareRepo\building tools\apache-maven-3.5.2
Create or export MAVEN bin folder location to PATH variable. For example: E:\SoftwareRepo\building tools\apache-maven-3.5.2\bin
Open terminal or cmd and run mvn --version to confirm maven is installed or not.
You may refer to the link to setup the JAVA_HOME for Linux -
https://docs.oracle.com/cd/E21454_01/html/821-2532/inst_cli_jdk_javahome_t.html
Setting up Maven again :
https://maven.apache.org/install.html
check whether the mvn -v command is working or not..
Then execute other commands with mvn..
Thanks :)
For mac or ubuntu users
Make sure java is installed, if you have installed java 1.7
echo 'export JAVA_HOME="$(/usr/libexec/java_home -v 1.7 -f)"' >> ~/.bash_profile
or java 1.8, change the version accordingly.
echo 'export JAVA_HOME="$(/usr/libexec/java_home -v 1.8 -f)"' >> ~/.bash_profile
Then
source ~/.bash_profile
Now check,
echo $JAVA_HOME
This should be pointing to correct java version.
I'm doing this for future me's bc after all the links in StackOverflow, the solution was to check mvn.cmd file on C:\Program Files\Maven\apache-maven-3.6.3\bin...
On line 52 it sets the JDK, but it didn't had the "/bin" where my OpenJDK 15 stored the java.exe
This fixed the issue on Windows 11 but it could serve as an idea to check on other OS. Hope that it helps!

Error: Failed to run "javac -version" while running cordova build

I use the JDK in my NetBeans Java webservice by just pointing the directory where I've downloaded it to the project on NetBeans. Cant I do the same to build my Ionic APK? I tried setting the JAVA_HOME inside .bashrc with this line
export JAVA_HOME=$HOME/Apps/jdk1.8.0_144
But it didnt work, I dont get any return from java -version in terminal.
Not only the JAVA_HOME environment variable should be set, but also JDK binaries should be on your PATH:
JAVA_HOME=$HOME/Apps/jdk1.8.0_144
export JAVA_HOME
export PATH="${JAVA_HOME}/bin:${PATH}"

Error: JAVA_HOME is not defined correctly (mvn clean package -DskipTest)

I am new to command line and Ubuntu.
I am trying to run this:
mvn clean package -DskipTest
as indicated on this site:
https://github.com/forcedotcom/dataloader/
I opened up Command line and typed.
I am getting error message:
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-oracle/bin/java
Any lead would be appreciated greatly.
Error: JAVA_HOME is not defined correctly.
Show you that JDK isn't installed correctly, you should reinstall JDK, see OpenJDK page, you can try to use following command:
sudo apt-get install openjdk-8-jdk
Have a look here: https://askubuntu.com/questions/175514/how-to-set-java-home-for-java
JAVA_HOME=/usr/lib/jvm/java-7-oracle
export JAVA_HOME
You can also set it in /etc/environment or ~/.profile or ~/.bash_profile etc. But check which version is installed on your system.
Or you download the JDK as tar, unpack it in your home and use that jdk (allwoes to have different versions installed and easy switching those).

How to help Unity3d engine to find JDK installed on my Linux machine?

I'm developing on Unity3d 5.2 a game which should be build for an Android. I use Ubuntu 14.04.
I used:
sudo apt-get install openjdk-7jdk
to install java.
Set $JAVA_HOME and $PATH variables in .bashrc like this:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk-i386/bin
Executed .bashrc:
source .bashrc
When I check system vars with:
echo $JAVA_HOME
echo $PATH
it gives me:
/usr/lib/jvm/java-7-openjdk-i386
/usr/lib/jvm/java-7-openjdk-i386/bin
I have installed android-sdk.
But still when I try to build for android in Unity it shows choose folder window, I choose my jdk installation but it gives me error:
"The path you specified does not look like a valid JDK installation. Android development requires at least JDK 7 (1.7), having JRE only is not enough..."
What am I doing wrong and how to fix it? Please, help!

Categories

Resources