Error: could not find libjava.so while checking for jps - java

I am using centOS 6.10
ls /usr/lib/jvm
O/P:
java-1.6.0-openjdk-1.6.0.41.X86_64
java-1.7.0-openjdk-1.7.0.181.X86_64
java-1.7.0-openjdk-1.7.0.261.X86_64
java -version
O/P:
java version "1.7.0_181"
while checking for jps I am getting like this,
jps
O/P:
Error: could not find libjava.so
Error: could not find Java SE Runtime Environment.
My bashrc file be like,
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261.X86_64/
export HADOOP_INSTALL=/usr/local/hadoop
export PATH=$PATH:$HADOOP_INSTALL/bin
I dont know why this error is popping. I am getting frustrated because of this I am searching the solution for more than 3 days. Any help would be much appreciated.
Thanks in advance!!

I found java-related processes are sometimes quirky when it comes to libraries.
First identify the path for libjava.so and confirm the lib and executable are the same, one of 32- or 64-bit:
file /path/to/libjava.so /other/path/to/jps
Next, for any process like jps as an example, run this:
ldd /some/path/jps
The runtime link-editor should list an abs path for each lib referenced by the executable, or an error if not found. When there is an error, the lib is missing or exists in a directory that's not within the link-editor's search path. For normal processes, setting LD_LIBRARY_PATH usually works, but java stuff is too often quirky. Try experimenting with cmd-lines or a script, eg:
#!/bin/bash
LD_LIBRARY_PATH=/usr/local/lib64 /full/path/to/jps $*
(replace /usr/local/lib64 with the leading path to libjava.so).
Note that an independent "export KEY=val" is not required, and would add info into the environ and gets inherited by any process that follows; as shown, the shell sets KEY=val only for the cmd-line.
Some java-related quirks are processes that either clear the environ or reset stuff like LD_LIBRARY_PATH within their own child process(es), or call execve() with a NULL envp, and the child then fails as you describe. In that case you may have to resort to moving libs to a specific dir, or modify a java-related config file which lists lib dirs.
Sometimes quick answers can be found with strace, made easier when limiting the output, eg:
strace -f -e execve,open jps

Related

Setting up Sublime Text up for Java and getting "bash: javac: command not found"

I am having trouble in setting up Sublime Text for Java programming.
When using the JavaC Build System, I am getting an error like this in the terminal:
bash: javac: command not found
[Finished in 0.1s with exit code 127]
[shell_cmd: javac “/home/vinays/Documents/HelloWorld.java”]
[dir: /home/vinays/Documents]
[path: /app/utils/bin:/app/sublime_merge/bin:/app/bin:/usr/bin]
Then I had made myself a new build system like this:
}
shell_cmd”: “java $file_name”,
“working_dir”: “${project_path:${folder}}”,
“path”: “/usr/bin/java”
}
Again it went wrong and shows:
/usr/bin/env: ‘bash’: No such file or directory
[Finished in 0.0s with exit code 127]
[shell_cmd: java HelloWorld.java]
[dir: /home/vinays/Documents]
[path: /app/utils/bin:/app/sublime_merge/bin:/app/bin:/usr/bin]
You've got a lot going wrong here, so lets take it in stages.
“bash: javac: command not found
[Finished in 0.1s with exit code 127]
[shell_cmd: javac “/home/vinays/Documents/HelloWorld.java”]
[dir: /home/vinays/Documents]
[path: /app/utils/bin:/app/sublime_merge/bin:/app/bin:/usr/bin]”
This is an indication that the sublime-build file you tried to use (perhaps the one that ships with Sublime) tried to invoke javac, but it was not found anywhere on the path.
You also included the following in your answer:
~$ which java
/usr/bin/java
This is an indication that java is indeed available on the path; this is the command that you use to execute a Java program.
Since you have java but do not seem to have javac, my guess would be that you installed a JRE (Java Runtime Environment) and not a JDK (Java Development Kit). The first is meant for running Java applications only, while the second actually contains the tools and additional files needed to compile Java code.
So, your best bet is to verify that you actually have a JDK installed (perhaps by executing which javac to see what it says).
Further to that, you also provided this sublime-build file:
{
"shell_cmd": "java $file_name",
"working_dir": "${project_path:${folder}}",
"path": "/usr/bin/java"
}
This is wrong for a couple of reasons. First, it's using java and not javac, so even if it did work and launch java, it would fail because java is for executing the compiled class file, not for compiling your code.
Secondly, path in a sublime-build file does not do what you think it does. Specifically, it tells Sublime to completely erase the contents of your PATH environment variable and then replace it with the content that you provide.
The PATH is for specifying the list of directories in which programs you want to run interactively live; here you've set it to the actual physical location of the java program itself (i.e. not a folder).
With that change in place, nothing can run any longer because the PATH is entirely invalidated. Hence your error here:
/usr/bin/env: ‘bash’: No such file or directory
[Finished in 0.0s with exit code 127]
[shell_cmd: java HelloWorld.java]
[dir: /home/vinays/Documents]
[path: /app/utils/bin:/app/sublime_merge/bin:/app/bin:/usr/bin]
This is the OS telling you that Sublime tried to run bash (the default shell), but it could not be found. It can't be found because the path was broken by your build (the path: listed is gathered for the debug diagnostic before the build starts, so it represents what the path was prior to the sublime-build file breaking it).
It's also worth noting that a command like javac Something.java just compiles the Java code, and then stops; this is almost certainly not what you want to do. You probably want to actually execute the code as well.
So, after you ensure that you actually have both java and javac, you should be able to get yourself up and running with a sublime-build file like this:
{
"shell_cmd": "javac \"$file_name\" && java \"$file_base_name\"",
"working_dir": "${project_path:${folder}}",
"selector": "source.java"
}
This will compile the single Java file and then, if it worked, execute it. Note that because your other build broke the PATH, you need to restart Sublime before any build will work.
This also doesn't help you work with any Java program that's more complicated than a single file. Java as a language does not lend itself well to ad-hoc compiling and running of files because the class files need to be in the appropriate package-specific location.
At some point you will need to upgrade yourself to using some Java-aware external build tool from Sublime, such as Ant or the like.
Yes Sir I have verified my system commands i had got the following result:
~$ which java
/usr/bin/java
~$ which javac
/usr/bin/javac
More Over My path in sublime text is also Like This:
{
"shell_cmd": "java $file_name",
"working_dir": "${project_path:${folder}}",
"path": "/usr/bin/java"
}

How do I set $PATH using PHP?

My site is being hosted on a shared server so I don't have su access. I needed to run a piece of code with java but it's not available on the server. So I got a self-extracting version of java and put it on the server in my home directory. Then I gave executable permissions to java and I try running the code. I have to use relative paths when running the file because of the restrictions of the server.
Trying to run the java file ../java/bin/java -jar 'javafile.jar' gives me the following:
error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
I looked and libjli.so is located at ../java/lib/i386/jli/libjli.so. So I'm thinking that because I'm running java using a relative path it doesn't exactly know how to look for the other files. I'm hoping that if I can add absolute/path/to/java/bin to $PATH then this issue will be resolved.
So once I'm running my PHP, I can use dirname(__FILE__) to get the full path of my java bin directory. I've tried the following code:
exec('export PATH='.$bin_path.':$PATH', $output, $return);
print_r(array(getenv('PATH'), $output, $return));
Prints:
Array(
[0] => /usr/local/admin/bin:/usr/local/admin/bin/servers:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/bin:/usr/bin,
[1] => Array(),
[2] => 0
)
So nothing was added to $PATH, no output was given, and the command returned a successful exit value. Is it just the restriction of the server that is preventing me from getting this working?
Firstly, this is not going to work.
exec('export PATH='.$bin_path.':$PATH', $output, $return);
It will launch a child process with a shell, run the export command in the shell, and then the shell will exit. But the export command only changes $PATH for that shell.
I'm not sure, but I suspect that you need to use putenv.
I'm hoping that if I can add absolute/path/to/java/bin to $PATH then this issue will be resolved.
Well, it could only help if you used a simple command name for invoking the java command.
And it would be simpler to just run java using the full absolute pathname; e.g. "/absolute/path/to/java/bin/java"

Cannot locate Java home

I'm writing an application that leverages jsvc to start up a Java service as a daemon. I need to use something like jsvc because my application utilizes ports under 1024 and yet I'd really like to not run it as root so that created files are owned by another user. I'd also like to keep dependencies and configuration to a minimum so that all the client needs is a JVM and the jsvc binary installed.
However, it seems that jsvc has one major catch; it can't detect the home folder of Java on a given Unix operating system, which is quite frustrating:
$ ./startup.sh
Cannot locate Java home
I have been able to work around the issue on Ubuntu at least by manually setting the JVM home directory:
jsvc ... -home /usr/lib/jvm/default-java/ ...
Is there any way to determine the Java home directory dynamically from a Bash script so I can make this work across most Unixes/Linuxes? I'd be able to sleep much better at night doing something like:
JAVA_HOME="$( ... )"
jsvc ... -home "$JAVA_HOME" ...
...rather than hard-coding for each individual operating system. Is there a way that, given a java binary, I can find the home directory of its JVM/JRE?
Not sure if this works across *nixes, but found this solution:
JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"
I've tested it on Ubuntu and it works, however it does not work for OSX.
My solution was compiling the native linux source as the main jsvc page says in
http://commons.apache.org/proper/commons-daemon//jsvc.html
Here is my step by step procedure
Download www.fightrice.com/mirrors/apache/commons/daemon/source/commons-daemon-1.0.13-src.tar.gz
Once you extract the file then go to ...../commons-daemon-1.0.13-src/src/native/unix
in terminal as a root do the following:
$ support/buildconf.sh
$ ./configure --with-java=/usr/lib/jvm/default-java
$ make
test generated jsvc binary app
$ ./jsvc -help
It works! cleanly.
Use dirname and which commands to find Java's bin directory:
echo `dirname \`which java\``
JAVA_HOME=`dirname \`which java\``
... Only works if Java is already on the $PATH.
One other way is :
type -p java
Expect this to return the correct JAVA installation folder.

64 Bit Java Path in Cygwin

Ok, so this is actually quite a long story, but i'll try and keep it pretty short. So I'm trying to get the WebOS SDK working on Windows using Cygwin. Well, it wasn't working. It kept complaining that i was using a 32 bit version of java instead of 64 bit. the explenation for that problem is pretty easy to figure out. my PATH variable was set wrong and was pointing to my 32 bit installation of Java. Simple solution YOU'D THINK. apparantly not. for some reason, despite my best efforts, i cannot get the 64 bit version of java written into the PATH variable. The problem:
Cygwin doesn't like spaces in the Path variable, even though the path variable is littered with spaces, it won't accept it when i add my own space. After a lot of googling, i've found multiple accurances of this problem, and multiple solutions. but none of them seem to work. i always get exactly the same error:
bash: /usr/local/bin:/usr/bin:/cygdrive/c/Program: No such file or directory
The error is pretty self explanetary, basically its not reading anything past the first space, and i have no such directory as C:/Program so it spits out an error, my question is how do i get it to except a space, because changing the name of the directory is not an option, too many things depend on it. heres what i've tried so far:
$PATH=$PATH:C:\PROGRA~1\Java\jre6
$PATH=$PATH:"'pwd'" (while in java directory)
$PATH=$PATH:/cygdrive/c/Program Files/Java/jre6/bin (hay, i had to try)
$PATH=$PATH:/cygdrive/c/"Program Files"/Java/jre6/bin
$PATH=$PATH:/cygdrive/c/Program\ Files/Java/jre6/bin (escape character was rumored to work
$PATH=$PATH:'/cygdrive/c/Program Files/Java/jre6/bin'
$PATH=$PATH:"`/cygdrive/c/Program Files/Java/jre6/bin`"
and i think that was it, if anyone knows how to actually do it properly (or improperly but working for all i care) it would be greatly appreciated
Thanks
--
Chris
You also have the option of using the cygpath tool to help. Cygpath can be used to convert from a Window's path to a Unix path, but that doesn't directly handle spaces, so you need to do a two step process, first eliminate the spaces by converting to a DOS (short) path name, then convert to a Unix style path:
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files\Java\jre6\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\PDK\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\SDK\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\SDK\bin\novacom")):${PATH}
The end result will be something like (short names may differ slightly):
/cygdrive/c/PROGRA~3/HPWEBO~1/SDK/bin/novacom:/cygdrive/c/PROGRA~3/HPWEBO~1/SDK/bin:/cygdrive/c/PROGRA~3/HPWEBO~1/PDK/bin:/cygdrive/c/PROGRA~1/Java/jre6/bin:....other path elements....
One thing to keep in mind when using this, cygpath generates an error if the provided path actually does not exist because it can not create the short path for a non-existent path.
What is nice about this approach is that if you set Windows environment variables (like for example JAVA_HOME) then you can use that environment variable in the convert operation inside the .bash_profile, since all Windows environment variables are visible when the profile is being loaded. So if you had in the Windows environment
JAVA_HOME=C:\Program Files\Java\jre
then the cygpath command can be
$(cygpath -u $(cygpath -m -s "${JAVA_HOME}\bin"))
which means you only ever need to update via the Windows settings if the java install changes.
In .bash_profile:
PATH=/cygdrive/c/Program\ Files/Java/jre6/bin/:${PATH}
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/PDK/bin
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/SDK/bin
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/SDK/bin/novacom
Adds the paths to your .bash_profile and both java and the webOS SDK tools should be available.

Mac User - How do I set CLASSPATHS in Mac (I'm working on a Lucene Demo)

I'm trying to get my Apache Lucene demo to work and I'm down to setting the classpath in this tutorial http://lucene.apache.org/java/2_3_2/demo.html
I've hunted the web and these wer the 2 solutions I found to set CLASSPATH:
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
and
setenv CLASSPATH ${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
The second one brings up a error
-bash: setenv: command not found
The first one seemed to accept ok but wen i tried the next step in the tutorial i got an error. The next step was to run the following:
Phil-hunters-MacBook:webapps philhunter$ java org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src
which gave me the error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/demo/IndexFiles
This leads me to believe my CLASSPATHS didnt set correctly. Would I be right in assuming this? I have tried other tutorials and demos and see to get this same error quite a bit. Im new to Lucene and relatively new to mac and Unix shell scripting. Anyone know if I am setting the CLASSPATH correctly and if thats the cause of the errors?
in the terminal type
$ vim ~/.bash_profile
edit the file and add one line:
export CLASSPATH=${CLASSPATH}:/usr/local/lucene-3.6.2/lucene-core-3.6.2.jar:/usr/local/lucene-3.6.2/contrib/demo/lucene-demo-3.6.2.jar;
make sure to change the path of yours.
In your way you lose to add lucene-demo-3.0.3.jar in your classpath.
When you set an environment variable like CLASSPATH then by default it only applies to the current process (i.e. the shell process itself) - it isn't available to the java process you launch in the next line. In order to make it available to other processes you need to "export" the variable. In this case you can use something like:
export CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
This basically says "set the CLASSPATH variable to its current value plus the location of the lucene jar, and make the new variable available to any processes launched from this shell".
However, with java the usual way of setting the classpath is to do it as part of the java command itself, using the -classpath or -cp options. In your case it would look something like:
Phil-hunters-MacBook:webapps philhunter$ java -cp /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src
As an aside, the error you see when using the setenv line is because setenv is the command used in the C shell to set environment variables, but the default Mac shell (and the shell you're using) is bash which doesn't recognise setenv and lets you know it doesn't recognise it with the error message: -bash: setenv: command not found.
i create a .bash_profile file in my home directory and do things like
export GRAILS_HOME=/usr/share/grails
...
export PATH=${GRAILS_HOME}/bin:${GROOVY_HOME}/bin:/usr/local/mysql-5.1.45-osx10.6-x86_64/bin:${PATH}
you can work of that to set the classpath -- these examples show how to declare an environment variable and how to use the variable in other variables.

Categories

Resources