I'm getting the error "/var/jenkins_home/tools/hudson.model.JDK/jdk8/bin/java: not found:" even though the path exists:
[edi-debatcher_master-LNI22Y2C5V3VECCBCFPVB3ZUWJJNMLK6LIFEQ6V3OYH52T74NU3A#2] Running shell script
+ echo PATH = /var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
PATH = /var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/var/jenkins_home/tools/hudson.model.JDK/jdk8/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
+ echo M2_HOME = /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3
M2_HOME = /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3
+ mvn -version
/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5.3/bin/mvn: exec: line 199: /var/jenkins_home/tools/hudson.model.JDK/jdk8/bin/java: not found
I am using the Jenkins Blue Ocean feature, GitHub Jenkinsfile. I have "jdk8" and "Maven 3.5.3" defined in Global Tool Configuration, "autoinstall" checked.
Here is my Jenkinsfile:
pipeline {
agent any
stages {
stage('Initialize') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
mvn --version
'''
}
}
stage('Build') {
steps {
sh 'mvn -Dmaven.test.failure.ignore=true install'
}
post {
success {
junit 'target/surefire-reports/**/*.xml'
}
}
}
}
tools {
maven 'Maven 3.5.3'
jdk 'jdk8'
}
post {
always {
deleteDir()
}
}
}
You are running a wrong version of the file (here java) for the system.
Problem:
The file is there and can not be executed. The error message is "No such file or directory"
Solution:
You are running the wrong file version for your system.
The problem can occur for example if you run your Jenkins installation in a Docker container with Alpine Linux, since Alpine uses musl libc. The Oracle Java binaries only run on glibc.
The problem was that the Oracle JDK autoinstall didn't really do anything on my system (confirmed by checking Jenkins' system properties for Java). I found that openjdk 1.8 happen to already be on that container, so I manually pointed JAVA_HOME to that instead of relying on the Oracle JDK autoinstall.
Once I changed the project JDK setting to system, my build progressed past this error.
Related
I and running Jenkins in a Docker Container on my mac (locally) as per these instructions -
https://hackmamba.io/blog/2022/04/running-docker-in-a-jenkins-container/
I have installed my jdk
enter image description here
and set my Java Home here -
enter image description here
This is my simple pipelime
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven '3.8.7'
}
stages {
stage('Example') {
steps {
sh 'echo ls '
sh 'echo $JAVA_HOME'
// Run Maven on a Unix agent.
sh 'mvn --version'
}
}
}
}
Every time I get this -
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
I have no idea of how to find the path Jenkins installed the jdk too when it automatically installed it.
Please help
I've tried changing the path for JAVA_HOME - but I don't know what it would be in this environemnt
Which docker image this container made of? if it's official jeknins docker image - java comes installed already, and you do not need to install it. (as long as you are not adding nodes/agents).
However, if you need to install it, the installation should be in a local path in the container. you can give a specific location for the installation:
~/installed-here/
then the path should be ~/installed-here/jdk....
and JAVA_HOME should point to this path (a local linux/win path that in the container)
I've been looking at this for days.
I've created an instance of Jenkins in Docker to run locally using this DockerFile -
`FROM jenkins/jenkins:2.346.2-jdk11
USER root
RUN curl -sSL https://get.docker.com/ | sh
RUN usermod -a -G docker jenkins
USER jenkins
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli --plugin-file /usr/share/jenkins/ref/plugins.txt
COPY seedJob.xml /usr/share/jenkins/ref/jobs/seed-job/config.xml
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false`
I have then installed the JDK in Jenkins
I have then installed Maven in Jenkins
I have then created a simple Pipeline to test for Maven
`pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven '3.8.6'
jdk 'openjdk-171'
}
stages {
stage('Example') {
steps {
sh 'mvn --version'
}
}
}
}
`
AND I get this message
"Could not open '/lib/ld-linux-aarch64.so.1': No such file or directory"
I've tried rebuilding from Scratch, followed youtube tutorials - still nothing
(I'm also running on a Mac). Any help massively appreciated!
I expect it to return the version number of Maven
ld-linux-aarch64.so.1 is the dynamic linker for the guest binary. If you have a dynamically linked guest binary then you need to tell the emulator about not just the binary itself but also the dynamic linker and all the dynamic libraries that the guest binary links to (usually by passing it an option to tell it about a directory which has all the libraries in the usual places they would be on the real filesystem of the guest).
For gem5 you can use --redirects and --interp-dir
I realize that this question is going to initially sound like a duplicate of some other questions, but none of the other questions I've looked at fixed my issue.
The short story is that I have a JRE and a JDK installed at different locations. I set JAVA_HOME to point to the JDK, yet ant seems to still search for tools.jar in the JRE location. I'm not sure if this has more to do with my ant installation/configuration, or my JDK installation/configuration.
Here's the long story:
Environment
I am running on Red Hat Enterprise Linux Server release 7.5 (Maipo) on an account that does not have sudo privileges to anything.
My JDK install
The machine already has the JRE installed at /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/jre/bin/java. I am not allowed to modify that install, but I can create my own java installation in a separate location.
The security requirements on my network are very stringent and I am only allowed to put specific pieces of software on the machine. It is possible to ask permission for other pieces of software, but I have to go through an approval process that is a huge pain. I have obtained permission to put JDK 1.8 from openJDK on the machine.
Since openJDK does not release tar balls of the whole installation and since I don't have sudo permissions I attempted to install the JDK by downloading java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64.rpm and java-1.8.0-openjdk-devel-1.8.0.172-13.b11.fc29.x86_64.rpm to /local/apps/openJDK8 and running (from /local/apps/openJDK8)
rpm2cpio < java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64.rpm | cpio -i --make-directories
rpm2cpio < java-1.8.0-openjdk-devel-1.8.0.172-13.b11.fc29.x86_64.rpm | cpio -i --make-directories
For some reason this doesn't seem to do a complete JDK install (I think I must be missing some dependencies). I discovered that libjava.so, libjvm.so, jvm.cfg, and the server folder were missing, so I just created some links to the JRE install that had them (run from local/apps/openJDK8):
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/jvm.cfg usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/jvm.cfg
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/libjava.so usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/libjava.so
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/libjvm.so usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/libjvm.so
ln -s /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/amd64/server usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/lib/amd64/server
That step makes me a little nervous, so it could be part of my problem. At any rate, javac and java seem to work fine.
ANT INSTALL
For my ant installation, I just downloaded a tar ball and extracted it to /local/apps/ant and then did:
export JAVA_HOME=/local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64
export ANT_HOME=/local/apps/ant/apache-ant-1.10.4
I didn't bother updating the path because for now I'm just using fully qualified paths for everything. My ultimate goal is to have Jenkins running all of this anyway and it just uses fully qualified paths.
Results
Now if I try to run ant, I get:
> /local/apps/ant/apache-ant-1.10.4/bin/ant
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/tools.jar
Buildfile: build.xml does not exist!
Build failed
The build.xml does not exist part is of course expected, but the inability to locate tools.jar needs to be resolved. The strangest part for me is that according to the error message, it is actually looking for it in the JRE installation location.
Since ant itself is just a shell script, I modified it to print out a little more information by adding the following lines to the end of the file so that it looks like:
echo Running $ant_exec_command $ant_exec_args
echo JAVA_HOME = $JAVA_HOME
echo JAVACMD = $JAVACMD
echo CLASSPATH = $CLASSPATH
echo LOCALCLASSPATH = $LOCALCLASSPATH
echo ANT_HOME = $ANT_HOME
echo ANT_LIB = $ANT_LIB
eval "$ant_exec_command $ant_exec_args"
Now the output is:
$ /local/apps/ant/apache-ant-1.10.4/bin/ant
JAVA_HOME is /local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64
Running exec "$JAVACMD" -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH"
JAVA_HOME = /local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64
JAVACMD = /local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/bin/java
CLASSPATH =
LOCALCLASSPATH = /local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar
ANT_HOME = /local/apps/ant/apache-ant-1.10.4
ANT_LIB = /local/apps/ant/apache-ant-1.10.4/lib
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/tools.jar
Buildfile: build.xml does not exist!
Build failed
So JAVA_HOME is clearly set. I can even verify further that ant is actually using the JAVA_HOME value that I set for at least some things because if I remove all of those links I created in my JDK install, it will complain that it can't find libjava.so.
So ant is clearly using my JDK install for at least a little bit, but still looking in the old JRE install for tools.jar.
Any ideas on what is going on?
Figured it out :)
This fix still feels a little more like a workaround than an actual fix, so if someone else has a better solution, I'd be interested to hear it.
I've browsed through the ant source code a bit and discovered that ant has a --launchdiag property which is helpful. Running with that gave me:
/local/apps/openJDK8/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-13.b11.fc29.x86_64/bin/java -classpath /local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar -Dant.home=/local/apps/ant/apache-ant-1.10.4 -Dant.library.dir=/local/apps/ant/apache-ant-1.10.4/lib org.apache.tools.ant.launch.Launcher --launchdiag
Launcher JAR= "/local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar"
Launcher JAR directory= "/local/apps/ant/apache-ant-1.10.4/lib"
java.home= "/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/jre"
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64/lib/tools.jar
tools.jar= "null"
Setting "java.class.path" to "/local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-antlr.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-swing.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-testutil.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-xalan2.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-junitlauncher.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-xz.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-junit.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-log4j.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-javamail.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-bsf.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-resolver.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-oro.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-bcel.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jai.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jsch.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jmf.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-commons-logging.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-launcher.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-jdepend.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-commons-net.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-netrexx.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-junit4.jar:/local/apps/ant/apache-ant-1.10.4/lib/ant-apache-regexp.jar"
Buildfile: build.xml does not exist!
Build failed
In the code I found that that java.home property comes from System.getProperty("java.home") which apparently is not the same thing as JAVA_HOME
By adding -Djava.home=$JAVA_HOME I was able to get it working
I am making Eclipse plugin that run alternative build from within Eclipse
(e.g. for project that have both pom.xml and build.gradle do run with mvn package or gradle build)
But entry point for both of them are batch .bat files on Windows and bash on Linux.
For Windows running from Java would look like
Runtime.getRuntime().exec("cmd /c start mvn");
but that will start new window, while I want it to see running in Eclipse Console.
There must be something like but in Eclipse way I guess. How to run such script from Eclipse and see output in Console?
This is meant to be alternative and not dependent on m2e and Gradle Integration.
Did just as for Node.js using full path to maven installation (that should be selected in Preferences). But it is weird that I needed to pass JAVA_HOME and M2_HOME, because otherwise I get JAVA_HOME not found or M2_HOME not found, just like when maven is not yet set up:
ERROR: M2_HOME not found in your environment.
Please set the M2_HOME variable in your environment to match the
location of the Maven installation
related code
public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate {
#Override
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
// skipped some argument processing
envp[idx++] = "JAVA_HOME=" + System.getProperty("java.home");
envp[idx++] = "M2_HOME=" + System.getenv("MAVEN_HOME");
String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to run/debug. See also #71 (output is less or no output)
Process p = DebugPlugin.exec(cmds, workingPath, envp);
// no way to get private p.handle from java.lang.ProcessImpl
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, Constants.PROCESS_MESSAGE);
Is there some more beautiful way to do that? Please add as an answer.
UPDATE: This does not fully solves the problem, see Java - process launched with Runtime.getRuntime().exec( cannot create temp file
I am using grunt-jsdoc to manage the execution of jsdoc command, which depends on Java and needs to have the JAVA_HOME environment variable set. Assuming they already have node.js and Java, I'm trying to limit the local developer setup (on either Linux or Windows) to:
Checkout the project
run npm install
I have this working on Linux by using the grunt-shell plugin and running a task like this right before the jsdoc task:
// left out the part where I don't execute this task if JAVA_HOME already set
shell: {
getjavahome_linux: {
command: 'readlink -f /usr/bin/java | sed "s:bin/java::"',
options: {
callback: function(err, stdout, stderr, cb) {
process.env.JAVA_HOME = stdout;
cb();
}
}
}
}
But I have not been able to find a similar command for Windows, to say nothing of other platforms. My question:
A) Is there a better approach in Grunt that does not require these platform-specific commands?
OR
B) If not, anyone have a Windows command that will do the equivalent of the Linux version above?
Note: actually setting JAVA_HOME inside the shell command does not work with grunt-jsdoc, but getting the output and setting process.env.JAVA_HOME works great.
The JAVA_HOME env var check becomes a simple warning since version 0.3.3 of grunt-jsdoc
And since version 0.5.0, it doesn't require the Java version of jdsoc anymore. It fully runs on node.js
On windows, I use cygwin shell (the git-bash version) to run Grunt where JAVA_HOME is set...
But it should work from the windows cmd, I've juste tried:
test.js
console.log(process.env.JAVA_HOME);
cmd.exe
set JAVA_HOME=D:\path
node test.js
displays the path