I have several programs running on Java that suddenly stopped working.
I ran the commands to start them at command line and nothing happens. When I ran: $java -version nothing happens either.
If a I run: whereis java the output is:
java: /usr/bin/java /etc/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz
And if I ran wheris {the program depending on java}, I get a similar output. For example, for fastqc software:
$whereis fastqc
fastqc: /usr/bin/fastqc /usr/bin/X11/fastqc /usr/share/fastqc /usr/share/man/man1/fastqc.1.gz
I have no idea what to do. Besides, I checked if java is properly installed by:
apt-get install default-jre
And the output was:
Reading package lists... Done
Building dependency tree
Reading state information... Done
default-jre is already the newest version.
The following packages were automatically installed and are no longer required:
ifeffit libbit-vector-perl libcarp-clan-perl libchemistry-elements-perl
libchemistry-formula-perl libconfig-inifiles-perl libdate-calc-perl
libdate-calc-xs-perl libdate-manip-perl libifeffit-perl libio-stringy-perl
libmath-combinatorics-perl libmath-derivative-perl libmath-round-perl
libmath-spline-perl libntdb1 libole-storage-lite-perl
libparse-recdescent-perl libreadonly-perl libreadonly-xs-perl
libregexp-common-perl libspreadsheet-writeexcel-perl
libstatistics-descriptive-perl libterm-readkey-perl libtext-english-perl
libtext-glob-perl libtie-ixhash-perl libtime-stopwatch-perl
libtk-filedialog-perl libtk-gbarr-perl libtk-histentry-perl libtk-pod-perl
libtk-splashscreen-perl libwwwbrowser-perl libxray-absorption-perl
libxray-scattering-perl linux-image-3.19.0-25-generic
linux-image-extra-3.19.0-25-generic perlindex pgplot5 python-ntdb
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
I also made update, remove and re-install; but nothing changes.
If you have any suggestions please... I am obviously NOT an advanced-informatician...so I do not know what to do.
Thanks!
Have you tried to restart? Usually a nice go to as a first pass at debugging.
Did you not accidentally rewrite your $PATH? i.e. java is still installed, but not in your default path anymore. So running java --version will also fail.
You could also try sudo apt-get install openjdk-7-jdk to install the development kit for java. This also contains jre so might fix things. But my first quess would be your $PATH is broken.
It looks that the problem was the two versions of java that I have installed. The programs I was trying to run needed an older version of java, and when I installed the newer it has been set to use it as default. I finally solved this out, changing the default version of jave to use:
update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1074 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1074 manual mode
Press enter to keep the current choice[*], or type selection number: 1
And that's it!
:)
Related
I've java 1.8.0_131 by default on my machine but also java 9, so can I run a compiled class with jdk-9? is it possible anything like this:
java -v path/to/jdk-9 myClass
Thanks
The java command actually invokes the JVM. That JVM starts up, and reads your classes, and runs what you tell it to run.
There is no way to tell the "starting" JVM to actually use a different JVM. java isn't some sort of wrapper that "later" invokes some binary. It is already the binary that starts the JVM.
In other words: what you are asking for isn't possible. A simple workaround can be to define "aliases" on the command line, like java-8 to start your java8 installation, and java-9 to point to that other installation.
By default java command call the installed java version which can be checked by command:
One way could be update the java:
sudo update-alternatives --config java.
O/P of above command:
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number:
In your case java 9 will also come. update java version and run java command.
Or you can do directly call your java9 script which you can find ${Java9 Installation Directory}/jre/bin/java -v class.
PS: Above description of commands is based on ubuntu.
I have several .jar files that run successfully when opened with Mac's built in 'Jar Launcher' (Version 15.0.1) but when ran from terminal they error out.
Looking online the error messages might be down to the incorrect version of Java being linked to the terminal version, so I'd like to check if the options set for 'Jar Launcher' and the Java used within terminal are the same.
Does there exist any way to do this?
This question is two years old, but as there is no answer to it, I thought I'd put my two cents here since I've had issues myself, and have made some observations.
It seems that the Jar Launcher doesn't necessarily use the same JVM version as the one shown by the command /usr/libexec/java_home: If there is a JRE /Library/Internet Plug-Ins/JavaAppletPlugin.plugin, then the Jar Launcher will use it and ignore anything in /Library/Java/JavaVirtualMachines.
I've solve my problem of version mismatch between the Jar Launcher and the terminal by removing the JRE:
Go to /Library/Internet Plug-Ins.
Remove the JavaAppletPlugin.plugin directory by executing the rm command as a root user or by using the sudo tool.
Go to /Library/PreferencePanes.
Remove JavaControlPanel.prefpane by executing the rm command as a root user or by using the sudo tool.
Source: https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-macos.htm
Please excuse what appears to be a question answered before, but if I read 10 different posts I find 20 different responses.
I just installed Fedora 25. I am going to be learning Java development and need to set up my environment. I will be using openjdk and have installed java-1.8.0-openjdk-devel. I will also be using Maven.
Now I need to set my $PATH and $JAVA_HOME variables.
I tried the answer found here (Fedora OpenJDK Set JAVA_HOME)
but after adding to my .bashrc
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and then testing, I get what appears to me to be the wrong answer because I do not think there should be a /jre/ on the end
> echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-1.b14.fc25.x86_64/jre/
So can I please ask what I should set JAVA_HOME to so that I do not need to update it with every openjdk update?
After that I think PATH is just
export PATH=$JAVA_HOME/bin:$PATH
this seems like such a straightforward thing to do yet it seems to me there is much confusion. thx
PS
also, is .bashrc even the correct place? because I see here (https://askubuntu.com/questions/175514/how-to-set-java-home-for-java) that /etc/environment would be more appropriate) thx
I suggest create an alias command, modifying bashrc and set JAVA_HOME
into bash_profile, this:
Create command in the bashrc:
alias set-java='sudo alternatives --config java;export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::");source ~/.bash_profile'
Save and execute: source ~/.bashrc
Create generic JAVA_HOME in bash_profile:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
PATH=$JAVA_HOME/bin:$PATH
Execute the alias command
Set JAVA_HOME :
echo "JAVA_HOME=/etc/alternatives/jre" >> ~/.profile
source ~/.profile
echo $JAVA_HOME
I put the following in ~/.profile, not ~/.bashrc and I think it's the same on Fedora (I used CentOS at work and do the same):
export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME=$JDK_HOME/jre
I have to either sign out or reboot after changing .profile.
On Ubuntu, java only changed from 7 to 8 a few years ago. I don't know why Fedora would want to put an exact version number on the java folder. You might complain?
If Java moves around too much for you on Fedora, use a symlink. The symlink takes affect right away, without logging out or rebooting. On my laptop, I encrypt my home folder, so for extra speed, I put most third party tools in a /tools/ folder and give myself account access to it (sudo chown -R myself.myself /tools/ where myself is my user ID). That's where I put my maven install. Tomcat uses a different directory name for each release, so I make a symlink like so:
cd /tools
ln -s apache-tomcat-8.0.38 latest-tomcat
Then in ~/.profile (CATALINA means TOMCAT in this example - don't ask me why):
# My un-encrypted Tools folder
export TOOLS=/tools
# Tomcat
export CATALINA_HOME=$TOOLS/latest-tomcat
# Maven
export M2_HOME=$TOOLS/apache-maven-3.3.9/
export M2="$M2_HOME"bin
export PATH=$PATH:$M2
When I upgrade tomcat:
cd /tools
rm -f latest-tomcat
ln -s apache-tomcat-8.0.39 latest-tomcat
You can use the same technique to make a /usr/lib/jvm/latest-java. In fact, if you install Oracle Java (not necessarily recommended), it does exactly that, for this reason.
Yes, what you said about the path looks correct to me. I don't put java in my path, preferring to use $JDK_HOME, $JAVA_HOME, or just calling maven. Part of that is for security. Part of it is to feel like I always know which version of Java I'm using.
P.S. To me, the ln -s syntax always looks as if the arguments are reversed. The actual folder name goes first, followed by your desired alias/link.
OpenJDK bundled with Fedora dosen't work for me. For example IntelliJ can't use this version. In my opinion, best option is to install Oracle JDK RPM from Oracle.
JDK location:
/usr/java/latest/
To manipilate JRE use command below:
sudo alternatives --config java
So far, this gets Android Studio running using the Fedora provided OpenJDK and respects the distribution provided materials without a bunch of otherwise unmanaged symlinking:
vim ~/.bash_profile
Add the following, or replace any existing examples that look similar to it:
export JAVA_HOME=$(readlink -f /usr/bin/java | cut -d/ -f1-6)
The command basically asks for the physical path that the symlink /usr/bin/java points to (configured by alternatives in Fedora), and then says "take the first 6 fields given to you by splitting on the / character."
Note that your $PATH will already be set up correctly for use with the Fedora provided OpenJDK.
In practice, this ends up looking like:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-8.fc28.x86_64/jre
This assumes you have at least one of the OpenJDK packages Fedora ships. 25 probably only shipped 1.8, 28 ships 1.8, 10.0.2, and 11.0.1. (if you're reading this and still using 25, it's probably time to upgrade.)
Install one of the java-*-openjdk-headless packages available to you (or one of the Oracle provided ones), and configure which one to use using:
sudo alternatives --config java
The default on my Fedora 28 install was to use OpenJDK 1.8.
Sadly I don't have Fedora available for me, so I can't investigate how Java is usually installed, but why you don't try to replace /usr/bin/java in your expression with something like /usr/bin/javac? The actual path to javac link you can get with
which javac
And read the real path with readlink. Obviously, it works if JDK is installed (not JRE).
About updating, most of Linux distros create a symbolic link like /usr/lib/jvm which is set to the correct directory and update in case of new version. For me better solution it to put this path in your bashrc.
And yes, bashrc is usually enough if you don't need JAVA_HOME to be visible to other OS users.
Maybe adding a tr could work? export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::" | tr -d "/jre/") ?
Also, setting it in your env var will make the var independent from the sh your using. That's a great way to store It.
I'm trying to build AOSP from source (With a few modifications) but my build stops with
[ 0% 1/35196] JarJar: out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-jarjar.jar
FAILED: /bin/bash -c "java -jar out/host/linux-x86/framework/jarjar.jar process external/conscrypt/jarjar-rules.txt out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-full-debug.jar out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-jarjar.jar"
Error: Could not find or load main class com.tonicsystems.jarjar.Main
ninja: build stopped: subcommand failed.
make: *** [build/core/ninja.mk:149: ninja_wrapper] Error 1
and i can't get to fix it. My source is hosted here and the path of external/jarjar is the stock one on googlesource.
Can anyone help?
I had the same problem until I realized that it's due to the wrong path where com.tonicsystems.jarjar.Main is located. At ~/android/system, JarJar's com.tonicsystems.jarjar class is located in:
external/jarjar/src/main/com/tonicsystems
When it should be
external/jarjar/src/main/java/com/tonicsystems
Like it's source (from GitHub)
src/main/java/com/tonicsystems/jarjar
P.S: I had to create the external/jarjar/src/main/java directory and then move the source.
I've run into this with an AOSP fork (I think Qualcomm's tree) before - that was caused by the Makefile fragments that generate the file lists for the jar files not dealing properly with localized versions of the "sort" utility (causing removal of important class files in addition to the duplicates that were supposed to be removed).
I don't remember all the details or the proper fix, but the workaround that got me going initially was simply disabling localization while building.
rm -rf out
export LANG=C
export LC_ALL=C
export LC_COLLATE=C
. build/envsetup.sh
lunch whatever
make droidcore -j8
What fixed this for me was something completely unrelated to jarjar itself.
I was building AOSP 7.1.1 on Ubuntu 20.04. The default python command on Ubuntu 20.04 points to python3 [1], but AOSP 7.1.1 builds using python (which is really python 2.7.5).
I updated my system with sudo apt install python which linked the python command to python2 correctly instead of python3. After this, I built successfully.
AOSP is shipped with python under the prebuilts/python directory and I'm still confused as to why the build system doesn't point to that python version.
Edit
I had more trouble with adjusting my system to use the correct version of python, ultimately I had to add python and python3 as alternatives.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
$ sudo update-alternatives --config python
Select python2
In Windows, JAVA_HOME must point to the JDK installation folder (so that JAVA_HOME/bin contains all executables and JAVA_HOME/libs contains all default jar libraries).
If I download Sun's JDK bundle and installs it in Linux, it is the same procedure.
However, I need to use Kubuntu's default OpenJDK package. The problem is that all executables are placed in /usr/bin. But the jars are placed in /usr/share/java. Since they are not under the same JAVA_HOME folder I'm having trouble with Grails and maybe there will be trouble with other applications that expect the standard Java structure.
If I use:
JAVA_HOME=/usr
All applications and scripts that want to use any Java executable can use the standard procedure call $JAVA_HOME/bin/executable. However, since the jars are in a different place, they are not always found (example: in grails I'm getting ClassDefNotFound for native2ascii).
On the other hand, if I use:
JAVA_HOME=/usr/share/java
None of the Java executables (java, javac, etc.) can be found.
So, what is the correct way of handling the JAVA_HOME variable in a Debian-based Linux?
Thanks for your help,
Luis
What finally worked for me (Grails now works smoothly) is doing almost like Steve B. has pointed out:
JAVA_HOME=/usr/lib/jvm/default-java
This way if the user changes the default JDK for the system, JAVA_HOME still works.
default-java is a symlink to the current JVM.
If you use alternatives to manage multiple java versions, you can set the JAVA_HOME based on the symlinked java (or javac) like this:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
The standard Ubuntu install seems to put the various Java versions in /usr/lib/jvm. The javac, java you find in your path will softlink to this.
There's no issue with installing your own Java version anywhere you like, as long as you set the JAVA_HOME environment variable and make sure to have the new Java bin on your path.
A simple way to do this is to have the Java home exist as a softlink, so that if you want to upgrade or switch versions you only have to change the directory that this points to - e.g.:
/usr/bin/java --> /opt/jdk/bin/java,
/opt/jdk --> /opt/jdk1.6.011
I modified one of the solution above and this seems to work no matter where java is installed, as long it's in your PATH.
JAVA_HOME=$( j=$( readlink -f $(which java) ) ; echo ${j%%/bin/java} )
I usually don't have any JAVA_HOME environment variable. Java can set it up itself. Inside java java.home system property should be available.
Try setting the JAVA_LIB variable also.
If you have issues with JAR files not being found I would also ensure your CLASSPATH is set to include the location of those files. I do find however that the CLASSPATH often needs to be set differently for different programs and often ends up being something to set uniquely for individual programs.
Updated answer that will solve your problem and also just a general good how-to for installing Oracle Java 7 on Ubuntu can be found here: http://www.wikihow.com/Install-Oracle-Java-on-Ubuntu-Linux
I've discovered similar problems with the openjdk-6-jre and openjdk-6-jre-headless packages in Ubuntu.
My problem was solved by purging the openjdk-6-jre and openjdk-6-jre-headless packages and re-installing. The alternatives are only updated on a fresh install of the openjdk-6-jre and openjdk-6-jre-headless packages.
Below is a sample of installing after purging:
aptitude purge openjdk-6-jre openjdk-6-jre-headless # to ensure no configuration exists
aptitude install --without-recommends openjdk-6-jre # Installing without some extras
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
ca-certificates-java{a} java-common{a} libavahi-client3{a} libavahi-common-data{a} libavahi-common3{a} libcups2{a} libflac8{a} libgif4{a} libnspr4-0d{a} libnss3-1d{a} libogg0{a} libpulse0{a} libsndfile1{a} libvorbis0a{a} libvorbisenc2{a} libxi6{a} libxtst6{a}
openjdk-6-jre openjdk-6-jre-headless{a} openjdk-6-jre-lib{a} tzdata-java{a}
The following packages are RECOMMENDED but will NOT be installed:
icedtea-6-jre-cacao icedtea-netx ttf-dejavu-extra
0 packages upgraded, 21 newly installed, 0 to remove and 119 not upgraded.
Need to get 0B/34.5MB of archives. After unpacking 97.6MB will be used.
Do you want to continue? [Y/n/?]
Writing extended state information... Done
Selecting previously deselected package openjdk-6-jre-lib.
(Reading database ... 62267 files and directories currently installed.)
Unpacking openjdk-6-jre-lib (from .../openjdk-6-jre-lib_6b24-1.11.5-0ubuntu1~10.04.2_all.deb) ...
...
Processing triggers for man-db ...
Setting up tzdata-java (2012e-0ubuntu0.10.04) ...
...
Setting up openjdk-6-jre-headless (6b24-1.11.5-0ubuntu1~10.04.2) ...
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/java to provide /usr/bin/java (java) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/keytool to provide /usr/bin/keytool (keytool) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/pack200 to provide /usr/bin/pack200 (pack200) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/rmiregistry to provide /usr/bin/rmiregistry (rmiregistry) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/unpack200 to provide /usr/bin/unpack200 (unpack200) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/orbd to provide /usr/bin/orbd (orbd) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/servertool to provide /usr/bin/servertool (servertool) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/tnameserv to provide /usr/bin/tnameserv (tnameserv) in auto mode.
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/lib/jexec to provide /usr/bin/jexec (jexec) in auto mode.
Setting up openjdk-6-jre (6b24-1.11.5-0ubuntu1~10.04.2) ...
update-alternatives: using /usr/lib/jvm/java-6-openjdk/jre/bin/policytool to provide /usr/bin/policytool (policytool) in auto mode.
...
You can see above that update-alternatives is run to set up links for the various Java binaries.
After this install, there are also links in /usr/bin, links in /etc/alternatives, and files for each binary in /var/lib/dpkg/alternatives.
ls -l /usr/bin/java /etc/alternatives/java /var/lib/dpkg/alternatives/java
lrwxrwxrwx 1 root root 40 2013-01-16 14:44 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/java
lrwxrwxrwx 1 root root 22 2013-01-16 14:44 /usr/bin/java -> /etc/alternatives/java
-rw-r--r-- 1 root root 158 2013-01-16 14:44 /var/lib/dpkg/alternatives/java
Let's contast this with installing without purging.
aptitude remove openjdk-6-jre
aptitude install --without-recommends openjdk-6-jre
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
ca-certificates-java{a} java-common{a} libavahi-client3{a} libavahi-common-data{a} libavahi-common3{a} libcups2{a} libflac8{a} libgif4{a} libnspr4-0d{a} libnss3-1d{a} libogg0{a} libpulse0{a} libsndfile1{a} libvorbis0a{a} libvorbisenc2{a} libxi6{a} libxtst6{a}
openjdk-6-jre openjdk-6-jre-headless{a} openjdk-6-jre-lib{a} tzdata-java{a}
The following packages are RECOMMENDED but will NOT be installed:
icedtea-6-jre-cacao icedtea-netx ttf-dejavu-extra
0 packages upgraded, 21 newly installed, 0 to remove and 119 not upgraded.
Need to get 0B/34.5MB of archives. After unpacking 97.6MB will be used.
Do you want to continue? [Y/n/?]
Writing extended state information... Done
Selecting previously deselected package openjdk-6-jre-lib.
(Reading database ... 62293 files and directories currently installed.)
Unpacking openjdk-6-jre-lib (from .../openjdk-6-jre-lib_6b24-1.11.5-0ubuntu1~10.04.2_all.deb) ...
...
Processing triggers for man-db ...
...
Setting up openjdk-6-jre-headless (6b24-1.11.5-0ubuntu1~10.04.2) ...
Setting up openjdk-6-jre (6b24-1.11.5-0ubuntu1~10.04.2) ...
...
As you see, update-alternatives is not triggered.
After this install, there are no files for the Java binaries in /var/lib/dpkg/alternatives, no links in /etc/alternatives, and no links in /usr/bin.
The removal of the files in /var/lib/dpkg/alternatives also breaks update-java-alternatives.
Ubuntu 12.04 this works...
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-i386/jre
As an update for fedora user , alternatives set current java directory to
/usr/java/default
so you have to set your JAVA_HOME to /usr/java/default to always have alternatives curent selection in your classpath
HTH !
I always tend to set the JAVA_HOME according to the /usr/bin/java.
JAVA_HOME="$(dirname -- "$(dirname -- "$(readlink -f /usr/bin/java)")")"
This way, both alternatives point to the same location
As far as I remember, I used the update-java-alternatives script instead of the update-alternatives. And it did set the JAVA_HOME for me correctly.
Please see what the update-alternatives command does (it has a nice man...).
Shortly - what happens when you have java-sun-1.4 and java-opensouce-1.0 ... which one takes "java"? It debian "/usr/bin/java" is symbolic link and "/usr/bin/java-sun-1.4" is an alternative to "/usr/bin/java"
Edit:
As Richard said, update-alternatives is not enough. You actually need to use update-java-alternatives. More info at:
https://help.ubuntu.com/community/Java
My correct target has always been to download it from Sun and just install it that way. Then you know exactly what directory everything goes in.
But if you'd prefer to stick with the odd way that Debian installs it, my best guess would be the parent directory just above where the java and javac binaries are located.
(since when you specify it in your path it's $JAVA_HOME/bin)
(So in your case it would be ... $JAVA_HOME/share and $JAVA_HOME would be /usr ?)
Eh, that doesn't sound right...
I'm interested to hear the answer to this too!