How do I setup https://jdk.java.net/10/ so Solr 7.5 can find it under the installation?
I am using linux Amazon Linux 2 AMI 2.0.20181008 x86_64 HVM gp2.
Questions
In what directory should I put the files. ex. /usr/local/java?
Where should I set JAVA_HOME so every user will get it also after a reboot.
Where should I set the path to java so every user will get it also after a reboot.
Any installation location should work as long as you set the correct JAVA_HOME path and add the binary path to your $PATH variable.
You can configure both globally by editing /etc/environment, which should take effect for all users after restarting your shell (you can shortcut that process by doing source /etc/environment when testing).
JAVA_HOME=/usr/local/java/jre_10....
There should already be a PATH entry there which you can modify to add the Java binary directory.
This can differ between different Linux distributions and shell versions. If your distribution (Amazon Linux used it earlier at least) doesn't support it, you can use /etc/profile.
Another option that many prefer is to add an executable shell script in /etc/profile.d/ that sets up the variables for you, as these scripts are invoked on each initialization of a shell for all users.
Related
I am trying to install the gem rjb and I have come across this error
extconf.rb:53:in <main>': JAVA_HOME is not set. (RuntimeError).
The following is the entire error log.
$sudo gem install rjb -v '1.4.9' --source 'https://rubygems.org/'
[sudo] password for santoshpavan:
Building native extensions. This could take a while...
ERROR: Error installing rjb:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/rjb-1.4.9/ext
/usr/bin/ruby2.5 -r ./siteconf20200411-19244-10jhs3k.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/$(RUBY_BASE_NAME)2.5
extconf.rb:53:in `<main>': JAVA_HOME is not set. (RuntimeError)
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.5.0/gems/rjb-1.4.9 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/rjb-1.4.9/gem_make.out
I tried the answer that is mentioned here.
When I printed the env I can see the JAVA_HOME path mentioned, as below.
santoshpavan#DESKTOP-ISVIQCL:/mnt/c/code/expertiza$ env
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
HOSTTYPE=x86_64
LESSCLOSE=/usr/bin/lesspipe %s %s
LANG=C.UTF-8
OLDPWD=/mnt/c
WSL_DISTRO_NAME=Ubuntu-18.04
JAVA_HOME=/mnt/c/Program Files/Java/jdk-10.0.2
S_COLORS=auto
USER=santoshpavan
RBENV_SHELL=bash
PWD=/mnt/c/code/expertiza
HOME=/home/santoshpavan
NAME=DESKTOP-ISVIQCL
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
SHELL=/bin/bash
TERM=xterm-256color
SHLVL=1
LOGNAME=santoshpavan
PATH=/home/santoshpavan/.yarn/bin:/home/santoshpavan/.config/yarn/global/node_modules/.bin:/home/santoshpavan/.rbenv/plugins/ruby-build/bin:/home/santoshpavan/.rbenv/shims:/home/santoshpavan/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu18.04onWindows_2020.1804.7.0_x64__79rhkp1fndgsc:/mnt/c/Python37/Scripts/:/mnt/c/Python37/:/mnt/c/Python27/:/mnt/c/Python27/Scripts:/mnt/c/Users/santo/AppData/Local/Programs/Python/Python37-32/Scripts/:/mnt/c/Users/santo/AppData/Local/Programs/Python/Python37-32/:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/libnvvp:/mnt/c/app/santo/product/12.1.0/dbhome_1/bin:/mnt/c/Program Files/Java/jdk-10.0.2/bin:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/nodejs/:/mnt/c/Program Files/NVIDIA Corporation/Nsight Compute 2019.4.0/:/mnt/c/Apache/apache-zookeeper-3.5.6-bin/bin:/mnt/c/Program Files/Java/jdk-10.0.2/bin:/mnt/c/Spark/spark-3.0.0-preview2-bin-hadoop2.7:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files/PostgreSQL/12/bin:/mnt/c/Program Files/PostgreSQL/12/lib:/mnt/c/Program Files/Intel/WiFi/bin/:/mnt/c/Program Files/Common Files/Intel/WirelessCommon/:/mnt/c/Users/santo/.cargo/bin:/mnt/c/Ruby27-x64/bin:/mnt/c/Program Files/Git/usr/local/bin:/mnt/c/Program Files/Git/bin:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/iCLS/:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/iCLS/:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/WINDOWS/System3:/mnt/c/Program Files/JetBrains/PyCharm Community Edition 2019.3.4/bin:/snap/bin
WSLENV=JAVA_HOME/p
LESSOPEN=| /usr/bin/lesspipe %s
_=/usr/bin/env
I do no understand the issue here as JAVA_HOME is present in the environment variables with the WSLENV.
Note:
Earlier, when I had the same error, following this helped. But the javac was still was not being detected. So, I installed java in wsl using $ sudo apt install default-jdk. And, after that this issue has happened.
TL;DR: In WSL, you must use javac.exe since it is a Windows binary. Simply typing javac will not work, even if the path is set up correctly. If that doesn't work, try adding ../bin to the end of your JAVA_HOME variable.
Using Windows Binaries & Environment Variables in WSL
If you have JavaSDK installed on Windows, you do not need to install Linux binaries. Simply ensure that they are properly linked so WSL knows where to find the SDK.
Also, when calling a Windows binary from WSL, you cannot type javac, you must type javac.exe so WSL knows we're looking in the Windows file system.
Ensure Java for Windows works
Open PowerShell or cmd.exe from any directory and type java --version
You should get a list of JRK info:
openjdk 11.0.4 2019-07-16 LTS
OpenJDK Runtime Environment Corretto-11.0.4.11.1 (build 11.0.4+11-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.4.11.1 (build 11.0.4+11-LTS, mixed mode)
Your version might be different, the important part is that the system knows where to find Java. If you get an error, ensure your Windows Environment variables are set correctly:
JAVA_HOME as an Environment Variable, and
JAVA_HOME/bin as a Path variable.
Setting Variable in WSL
The best place to put the next lines of code are in your .bashrc file (I have mine right before sourcing my aliases & functions), but if you are running multiple users or simply prefer ./bash_profile or /etc/profile put it there.
# Shared environment variables
export JAVA_HOME=/mnt/d/Java/jdk11.0.4_10
While we're at it, add any other Environment Variables you will need in your development setup.
I have my WSL, Java, and all my other dev tools set up on my second HDD which is not a system drive, ensure that your location matches your JAVA_HOME path in Windows.
If JavaSDK is located at: C:\Java\jdk8.0
The corresponding WSL mount point is: /mnt/c/Java/jdk8.0
Executing
Important: Use java.exe <args> in WSL instead of java <args>
Say you just wrote CompareTwoStrings.class and want to compile and run it using the Windows binaries. You can do it from a Windows shell or WSL.
From Windows Shell:
javac GetStringLength.java
java GetStringLength
From WSL:
javac.exe GetStringLength.java
java.exe GetStringLength
Using java <args> in WSL will result in a Command 'java' not found error. That is because running windows binaries from within WSL requires that the .exe extension is used in the command.
Simplicity
We don't want to install a second copy of Java specific to WSL and waste that precious disk space, so we're going to call the Windows binary from the WSL shell. This is a great benefit of WSL (WSL1 in particular) in that it can interact (almost) flawlessly with the Windows File System.
NOTE: In order to run a program, it must either be a Path variable, or be run from within it's containing folder.
Hopefully that works as easily for you as it did for me. Just remember to use the correct command depending on what OS binary you're running. This took me about 10 minutes to get set up, and has been a lifesaver for cross-compiling and general ease-of-use.
In order to build some Android projects, it's necessary to set the environment variable JAVA_HOME. (See this Stack Exchange question and flutter bug report.)
This is the case for a project I'm working on. I would like to change the Gradle file so it is not necessary to set JAVA_HOME.
Is there any way for Gradle to get the path to the JDK used by the enclosing Android Studio process (or for the process to pass in the JDK without user intervention)? This should work when JAVA_HOME had not been set.
you can define a task in your_project_path/app/build.gradle
task javaHome {
println "JAVA_HOME:" + System.getProperty("java.home")
}
run task:
./gradlew -q app:javaHome
RESULT:
JAVA_HOME:/usr/lib/jvm/java-8-openjdk-amd64/jre
There are generally two options available:
a) Edit the gradle.properties file and define which JDK you want to use:
org.gradle.java.home=(path to JDK home)
There it cannot be set dynamically, because it's an egg/hen problem.
And it might also fail on other computers, because the path may vary.
But one can pass it as command-line option:
./gradlew -Dorg.gradle.java.home=$JAVA_PATH
For reference: Build Environment.
b) However, one can also add an export JDK_HOME statement on top of file gradlew. Came up with a shell script, which can at least detect the default JDK install on Linux (Android Studio runs on JRE):
tmp=`which java`
export JAVA_HOME=${tmp::-9}
echo $JAVA_HOME
/usr/java/jdk1.8.0_172
Of course, one also would have to consider no JDK being present at all:
/usr/bin/which: no java in ...
Generally, this assumes a default JDK had been set with alternatives, as a package manger usually would do; eg yum install jdk1.8.0_102.x86_64. The problem here is, that there is no easy way to identify which JDK path to use on Windows, because Windows has no which command and one would likely have to read from the registry. A helper PS script or executable could look up the value and truncate as required, called from file gradlew.bat. There still may be other ways to get the path.
(I already examined the answers here and here, but that doesn't answers my question)
I copied Java's folders (JRE & JDK) to a local folder and I manage to run .jar application by this command:
SomeFolder\Java\jre6\bin\javaw.exe -jar SomeApp.jar
But how can I run .exe application (e.g. eclipse.exe) by a similar way in two cases:
The application required only JRE
The application required also JDK
p.s. unfortunately "portableapps.com" solution is not acceptable.
The problem with .exe files is that they typically search the Java runtime on their own and there is no generic way to tell all of them where it is located.
In case of eclipse you can though e.g. by editing the eclipse.ini file.
Add
-vm
/usr/lib/jvm/java-7-oracle/bin
to the beginning of the file (with your path) and it should now start using the runtime you have specified.
A generic solution would be to figure out how the exe file runs the java code and then run it manually via javaw.exe -jar - that might not be possible if the exe file has the java code included and extracts it on demand. There are on the other hand versions as plain jar (often the version for Linux) that don't need all the exe workarounds.
Long story short...
1) Copy an installed version of the JDK (from another computer) you want to run to the destination computer.
2) Create a batch file to create or modify your environment variables, such as CLASSPATH, JAVA_HOME, and PATH.
#rem CONTENT OF BATCH FILE
#echo off
#cls
SET JAVA_HOME= <-- your JDK location
SET CLASSPATH=.;%JAVA_HOME%
SET PATH=%PATH%;%JAVA_HOME%\bin
3) Run this batch file before you launch Eclipse, or any executable that depends on the Java location. (Don't close the Command window or these transient values will vanish.)
4) You can close the Command window when you no longer need it.
This has worked for me since most Java dependent programs look for the JAVA_HOME variable in your computer's environment the path to Java binaries.
Have fun!
I want to change memory configuration of Tomcat. I know it can be done at
Start > Apache Tomcat > Configure Tomcat > Java Tab] as can be seen below
and specifying options like
-Xms512m
-Xmx1024m
-XX:MaxPermSize=512m
-XX:MaxHeapFreeRatio=70
there.
However this program group is created if I install Tomcat from an executable. I have installed Tomcat by simply extracting the zip which does not create Program group. So now where can I specify this information
With regards to the question of where Tomcat's memory options are saved when using the service version, on my machine at least they can be found in the Windows Registry at:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat-6\Parameters\Java
Initial memory and Maximum memory are recorded against the JvmMs and JvmMx values, while the options text is recorded against the Options value.
The Tomcat-6 portion of the address on mine is, I believe, based on the identifier I gave to the service (i.e. within the service manager Tomcat is named "Apache Tomcat 6.0 Tomcat-6"), and you may not need to go through Wow6432Node depending on whether you're using 32-bit or 64-bit Tomcat.
I'm assuming here that they haven't made any dramatic changes in where this information is stored in versions of Tomcat more recent than Tomcat 6.
Ohkay while digging inside Tomcat I found some information in one of its txt files (point 3.4) and online:
Apart from CATALINA_HOME (which is set to apache-tomcat-x.x.x directory, for e.g. C:\Program Files\Apache Software Foundation\apache-tomcat-7.0.41) and CATALINA_BASE (optional, defaults to CATALINA_HOME), all environment variables can
be specified in the setenv script. The script is placed either into
CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named
setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be
readable.
By default the setenv script file is absent. If the script file is present
both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is
preferred.
For example, to configure the JRE_HOME and CATALINA_PID variables you can
create the following script file:
On Windows, %CATALINA_BASE%\bin\setenv.bat:
set "JRE_HOME=%ProgramFiles%\Java\jre6"
exit /b 0
On *nix, $CATALINA_BASE/bin/setenv.sh:
JRE_HOME=/usr/java/latest
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
To set Java options for memory allocation for web app, add something like following (as per memory requirements of your application) to the same file
set JAVA_OPTS="-Xms256m -Xmx512m"
The CATALINA_HOME and CATALINA_BASE variables cannot be configured in the
setenv script, because they are used to locate that file.
All the environment variables described here and the setenv script are
used only if you use the standard scripts to launch Tomcat. For example, if
you have installed Tomcat as a service on Windows, the service wrapper
launches Java directly and does not use the script files.
I'm not sure if it is best practice but I add MySQL-connector jar to the extensions directory of my Java install directory to I can easily connect to MySQL databases.
I also set environment variables to point to various directories so that I can develop on different machines and only define environment variables locally and code doesn't have to be modified for file paths.
In either case of the above I find that unless I reboot my computer java does not recogise either. What happens during a reboot to Java? Is some config file updates by a java process? Can you update this without having to reboot?
To test this I have created a new environment variable on both Mac (adding to .MacOS/environment.plist), Linux (Ubuntu 12.04) and windows 7 (via control panel). I then used System.getenv("TestVar"); which returns null. Running set from the command line shows it exists though. After a reboot System.getenv("TestVar"); returns the expected value.
Ultimately your goal is to include jar files in CLASSPATH . its up to you how include jars in classpath but this is not good practice to put jars inside extensions directory . While running your program modify CLASSPATH value .
java -cp jar1:jar2:jar3:dir1:. HelloWorld
java -classpathjar1:jar2:jar3:dir1:. HelloWorld
As far as setting environment variables goes the on Ubuntu a log out is required
https://superuser.com/questions/339617/how-to-reload-etc-environment-without-rebooting