Setting JAVA_HOME on centos for root and normal user --> checking java -version - centos

actually i im learning Linux (CentOs 7). I installed Java on root (usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre/bin/java).
Now i have one question. if i type "java-version" i get
[mibe#localhost ~]$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
I thought that java only works if i set the JAVA_HOME PATH in /etc/profile. Why do i get a result for this call?

Because you installed java in /usr/lib, this folder is in system environment. When you type java -version, the system can find the command java.
But if you install java in other folder not in system environment, you must set the JAVA_HOME PATH in /etc/profile to tell the system how to find the java command, and there are other important reasons why to set the JAVA_HOME not just for this.
https://stackoverflow.com/a/27996647/11559693

Related

Ubuntu eclipse javadoc does not show

When using eclipse I get:
The Javadoc for this element could neither be found in the attached source nor the attached Javadoc.
when hovering over code even for classes like java.lang.String.
Pressing Ctrl and selecting Open Declaration or Open Implementation yields:
I am running Ubuntu 20.04.1 LTS using eclipse version 2020-09 (4.17.0) and have java OpenJDK installed:
$ java --version
openjdk 13.0.4 2020-07-14
OpenJDK Runtime Environment (build 13.0.4+8-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 13.0.4+8-Ubuntu-120.04, mixed mode)
Clicking on Change Attached Source... in String.class (image above) I get this:
I cannot seem to get it to work. Any help is appreciated!

how to upgrade javac in Debian

could someone suggest elegant way to upgrade javac in Debian to version 8 ?!
javac -version
javac 1.7.0_261
java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
to those who needs elegant solution:
download JVM from oracle: http://java.sun.com/products/archive/
if you use Linux as I do, *.tar.gz file can be chosen (it has all related binaries)
in Debian or other Linux untar it with command "tar xvzf PACKAGENAME.tar.gz", as a result all folders and subfolders will be created in related new folder, e.g. jdk-8u251-linux-x64. Related version of javac is in "dk-8u251-linux-x64/bin/" subfolder
copy this all structure e.g. "jdk-8u251-linux-x64" e.g. to /home/user1
modify PATH variable to allow system find related new javac: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user1/jdk1.8.0_251/bin/
old javac can be renamed as a backup: mv /usr/bin/javac /usr/bin/javac_old
verification of the result:
javac -version
javac 1.8.0_251
Now javac on my system has the same version as java (as mentioned above, before they were quite different). In version 8 Java have several changes, e.g. some new ways how Time is handeling, which forced me to such changes.

Where is Java 6u65-apple installed?

I see that Java 6u65-apple is one of the available Java versions. Where does this JDK get installed on macOS? Will this JDK coexist with the newer (newest) Oracle Java JRE and JDK?
I tried what you intend using sdkman on macOS High Sierra. It should install it below ~/.sdkman but it seems not to work. This is what I and some others get, see for example https://gitter.im/sdkman/user-issues?at=5a1db5de71ad3f87363f4754
$ sdk install java 6u65-apple
tr: Illegal byte sequence
Apple requires that you agree with the Apple Software License Agreement
prior to installation.
The license agreement can be found in PDF format here:
http://images.apple.com/legal/sla/docs/JavaForOSX.pdf
Do you agree to the terms of this agreement? (Y/n): Y
Downloading: java 6u65-apple
In progress...
######################################################################## 100.0%
Binary validation passed...
We will be needing super powers...
Repackaging Java 6u65...
Attaching to the DMG...
Mounting DMG as Volume...
Volume(s) mounted successfully
Installing PKG inside DMG...
installer: Cannot install on volume / because it is disabled.
installer: Es ist bereits eine neuere Version dieses Pakets installiert.
Copy JDK Home to temp folder...
cp: /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home: No such file or directory
unlink: /Users/gg/.sdkman/tmp/out/java-6u65-apple/bundle: No such file or directory
ln: /Users/gg/.sdkman/tmp/out/java-6u65-apple/bundle: No such file or directory
Preparing archive...
zip error: Nothing to do! (try: zip -qr --symlinks /Users/gg/.sdkman/tmp/.zip . -i .)
Unmounting volume...
"/Volumes/Java for OS X 2015-001" unmounted successfully.
Done repackaging...
mv: rename /Users/gg/.sdkman/tmp/.zip to /Users/gg/.sdkman/archives/java-6u65-apple.zip: No such file or directory
unzip: cannot find or open /Users/gg/.sdkman/archives/java-6u65-apple.zip, /Users/gg/.sdkman/archives/java-6u65-apple.zip.zip or /Users/gg/.sdkman/archives/java-6u65-apple.zip.ZIP.
rm: /Users/gg/.sdkman/archives/java-6u65-apple.zip: No such file or directory
Stop! The archive was corrupt and has been removed! Please try installing again.
So I found on http://osxdaily.com/2017/06/29/how-install-java-macos-high-sierra/ a link to https://support.apple.com/kb/dl1572?locale=en_US and just clicked "Download" and it does install JDK6 inside /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/ as expected. And you can switch as you like:
$ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
$ export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
And since javac 1.6 worked fine and this was the only reason for looking into sdkman I removed it entirely.

:javap -p <classname> returns IlegalArgumentException

Getting below error in Scala REPL
scala> :javap -p Add
java.lang.IllegalArgumentException: requirement failed
at scala.Predef$.require(Predef.scala:264)
at scala.tools.nsc.interpreter.JavapClass$JavapTool$.apply(JavapClass.scala:337)
at scala.tools.nsc.interpreter.JavapClass.tool$lzycompute(JavapClass.scala:37)
at scala.tools.nsc.interpreter.JavapClass.tool(JavapClass.scala:37)
at scala.tools.nsc.interpreter.JavapClass.apply(JavapClass.scala:49)
at scala.tools.nsc.interpreter.ILoop.javapCommand(ILoop.scala:332)
at scala.tools.nsc.interpreter.ILoop.$anonfun$standardCommands$6(ILoop.scala:187)
at scala.tools.nsc.interpreter.LoopCommands$LineCmd.apply(LoopCommands.scala:132)
at scala.tools.nsc.interpreter.LoopCommands.colonCommand(LoopCommands.scala:103)
at scala.tools.nsc.interpreter.LoopCommands.colonCommand$(LoopCommands.scala:101)
at scala.tools.nsc.interpreter.ILoop.colonCommand(ILoop.scala:44)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:696)
at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:416)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:437)
at scala.tools.nsc.interpreter.ILoop.$anonfun$process$1(ILoop.scala:1012)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:909)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:75)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:88)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:99)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:104)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
That entry seems to have slain the compiler. Shall I replay
your session? I can re-run each line except the last one.
[y/n]
Abandoning crashed session.
Please share if anyone encountered this issue & able to resolve. Below is the versions information. Thanks in advance!
C:\Users\email>scala -version
Scala code runner version 2.12.2 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.
C:\Users\email>java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
As the answer said Why does installing Scala require additionally installing JDK?
Maybe you just installed Jre not JDK.
To solve the problem, install the corresponding version JDK.
:javap command within Scala REPL invoke the javap tool installed by JAVA SDK via java.util.spi.ToolProvider[ver2.13.1]. Jre don't include those JDK tools such as javap, jdb, jar.

Android build Ubuntu 16.04.1 required BlockingQueue

I am trying to build the Android source Build: LMY48M (android-5.1.1_r14) on Ubuntu 16.04.1
Got the following error
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/java/util/concurrent/ScheduledThreadPoolExecutor.java:9: warning: [unchecked] unchecked conversion
public ScheduledThreadPoolExecutor(int corePoolSize, java.util.concurrent.ThreadFactory threadFactory, java.util.concurrent.RejectedExecutionHandler handler) { super(0,0,0,(java.util.concurrent.TimeUnit)null,(java.util.concurrent.BlockingQueue)null,(java.util.concurrent.ThreadFactory)null,(java.util.concurrent.RejectedExecutionHandler)null); throw new RuntimeException("Stub!"); }
^
required: BlockingQueue<Runnable>
found: BlockingQueue
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
#### make failed to build some targets (01:15:26 (hh:mm:ss)) ####
I am using OpenJDK-7
P.S: I was intented to build on Ubuntu 14.04, however I am using a skylake processor that doesn't have support on Ubuntu 14.04.
However, I successfully build the same Android build on a virtual box running Ubuntu 14.04 on this same machine.
Any help is appreciated.
Update#2
By following #Nir Duan suggestion, I am using OracleJDK7. but as soon I run make -j32 I am getting this error,
You asked for an OpenJDK 7 build but your version is
java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode).
************************************************************
build/core/main.mk:191: *** stop. Stop.
You're problem is because you need Oracle JDK7 and not OpenJDK-7 when building the source.
Use these commands:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
The result of $ java -version should be this:
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
(If not look here and change default java version)