- What is JAVA_HOME? How does the JVM find the javac path stored in JAVA_HOME?
- 10 Answers 10
- How to Find JAVA_HOME
- 1. Introduction
- 2. Windows-Specific Ways to Find JAVA_HOME
- 3. macOS and Linux-Specific Ways to Find JAVA_HOME
- 4. Using Java to Find JAVA_HOME
- 5. Conclusion
- JAVA_HOME : where is java installed
- 3 Answers 3
What is JAVA_HOME? How does the JVM find the javac path stored in JAVA_HOME?
I would like to know what JAVA_HOME is. Where do I set the path of javac.exe and java.exe. It is in environment variables? When I compile a Java program from command prompt, how does the JVM find javac.exe ?
10 Answers 10
JVM does not find java.exe . It doesn’t even call it. java.exe is called by the operating system (Windows in this case).
JAVA_HOME is just a convention, usually used by Tomcat, other Java EE app servers and build tools such as Gradle to find where Java lives.
The important thing from your point of view is that the Java /bin directory be on your PATH so Windows can find the .exe tools that ship with the JDK: javac.exe , java.exe , jar.exe , etc.
JAVA_HOME basically to the root of JRE or JDK, while path is a separate story that makes you available executable files.
It happens that if you have JAVA_HOME, the program java will actually respect that and forward the command to whatever JRE is defined there. So it is not only 3rd parties who respect JAVA_HOME, java itself does. Check this explanation: clojureverse.org/t/…
JAVA_HOME and JRE_HOME are not used by Java itself. Some third-party programs (for example Apache Tomcat) expect one of these environment variables to be set to the installation directory of the JDK or JRE . If you are not using software that requires them, you do not need to set JAVA_HOME and JRE_HOME . PATH is an environment variable used by the operating system (Windows, Mac OS X, Linux) where it will look for native executable programs to run. You should add the bin subdirectory of your JDK installation directory to the PATH , so that you can use the javac and java commands and other JDK tools in a command prompt window. Courtesy: coderanch
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_24 classpath=C:\Program Files\Java\jdk1.6.0_24\lib\tools.jar path=C:\Program Files\Java\jdk1.6.0_24\bin
The command prompt wouldn’t use JAVA_HOME to find javac.exe, it would use PATH.
JAVA_HOME is a environment variable (in Unix terminologies), or a PATH variable (in Windows terminology). A lot of well behaving Java applications (which need the JDK/JRE) to run, looks up the JAVA_HOME variable for the location where the Java compiler/interpreter may be found.
JAVA HOME is used for setting up the environment variable for JAVA. It means that you are providing a path for compiling a JAVA program and also running the same. So, if you do not set the JAVA HOME( PATH ) and try to run a java or any dependent program in the command prompt.
You will deal with an error as javac : not recognized as internal or external command . Now to set this, Just open your Java jdk then open bin folder then copy the PATH of that bin folder.
Now, go to My computer right click on it—-> select properties——> select Advanced system settings——>Click on Environment Variables——>select New——>give a name in the text box Variable Name and then paste the path in Value.
JAVA_HOME is an environment variable which is read by some development tools like Apache Tomcat, Apache Maven, Gradle, Jenkins etc. Usually, JAVA_HOME is set to point to JDK instead of JRE because these development tools need to use tools like compiler, debugger, document generator etc. which are only available in JDK since JDK is a development kit. JRE is only meant for running java applications. JDK = JRE + Development tools
Consumer facing Java applications don’t read JAVA_HOME variable and they just need to know where the JVM is located and that’s why JVM location (directory) needs to be added to the PATH variable. This is automatically done for you when you install Java software. Whenever you try to run a Java application by either double clicking on the app or through command line, your operating system reads PATH variable to locate and run JVM and it doesn’t look for JAVA_HOME variable.
How to Find JAVA_HOME
The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.
To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.
Connect your cluster and start monitoring your K8s costs right away:
We rely on other people’s code in our own work. Every day.
It might be the language you’re writing in, the framework you’re building on, or some esoteric piece of software that does one thing so well you never found the need to implement it yourself.
The problem is, of course, when things fall apart in production — debugging the implementation of a 3rd party library you have no intimate knowledge of is, to say the least, tricky.
Lightrun is a new kind of debugger.
It’s one geared specifically towards real-life production environments. Using Lightrun, you can drill down into running applications, including 3rd party dependencies, with real-time logs, snapshots, and metrics.
Learn more in this quick, 5-minute Lightrun tutorial:
Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.
The Jet Profiler was built for MySQL only, so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.
Critically, it has very minimal impact on your server’s performance, with most of the profiling work done separately — so it needs no server changes, agents or separate services.
Basically, you install the desktop application, connect to your MySQL server, hit the record button, and you’ll have results within minutes:
DbSchema is a super-flexible database designer, which can take you from designing the DB with your team all the way to safely deploying the schema.
The way it does all of that is by using a design model, a database-independent image of the schema, which can be shared in a team using GIT and compared or deployed on to any database.
And, of course, it can be heavily visual, allowing you to interact with the database using diagrams, visually compose queries, explore the data, generate random data, import data or build HTML5 database reports.
The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.
To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.
Connect your cluster and start monitoring your K8s costs right away:
We’re looking for a new Java technical editor to help review new articles for the site.
1. Introduction
In this quick tutorial, we’ll learn how to find JAVA_HOME on Windows, Mac, and Linux.
As we all know, JAVA_HOME is an environment variable that we commonly use to locate java executables, like java and javac.
2. Windows-Specific Ways to Find JAVA_HOME
If we’re using Windows as the operating system, first we need to open up our command line (cmd) and type:
If JAVA_HOME is defined in our environment, then the above command will print it out.
Or to show the location of the java executable, we can try:
3. macOS and Linux-Specific Ways to Find JAVA_HOME
If we’re using either macOS or Linux, we can open up our terminal and type:
If JAVA_HOME is defined in our environment, then the above command will print it out.
This probably just shows us /usr/bin/java, which really isn’t very helpful since it’s a symbolic link. To unravel this, we’ll use dirname and readlink.
dirname $(dirname $(readlink -f $(which javac)))
$(dirname $(readlink $(which javac)))/java_home
This command prints the currently used java folder.
4. Using Java to Find JAVA_HOME
If we’re able to run java ourselves, then we have a nearly platform-independent way as well:
java -XshowSettings:properties -version
Running this command outputs numerous properties, one of them being java.home.
To parse it though, we’ll still need a platform-specific tool.
For Linux and macOS, we’ll use grep:
java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'
For Windows, we’ll use findstr:
java -XshowSettings:properties -version 2>&1 | findstr "java.home"
5. Conclusion
In this brief article, we learned how to find JAVA_HOME on different operating systems.
If this didn’t work though, it’s possible we didn’t set the JAVA_HOME variable properly while installing Java.
Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.
The Jet Profiler was built for MySQL only, so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.
Critically, it has very minimal impact on your server’s performance, with most of the profiling work done separately — so it needs no server changes, agents or separate services.
Basically, you install the desktop application, connect to your MySQL server, hit the record button, and you’ll have results within minutes:
JAVA_HOME : where is java installed
I’m trying to set the JAVA_HOME to get tomcat 7 to work with no success. I’m using CentOS 6.3. Here is what I did so far: which java /usr/bin/java so I edited the .bash_profile, I added export JAVA_HOME=/usr/bin/java didn’t work. I searched online and found another user on stackoverflow who found it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java I searched on my computer and found that java is located in /usr/lib/jvm/jre-1.6.0-openjdk/bin I then changed the JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/bin , tried to start tomcat but server can’t be found. How do I find where java was installed? I didn’t install it myself; it was installed during linux installation. Thanks in advance, Mike
JAVA_HOME is the directory that contains the bin directory, in this case /usr/lib/jvm/jre-1.6.0-openjdk .
I cd into the directory that tomcat was extracted to, then I type bin/startup.sh I was told to start 2 terminals. Type tail -f /server/apache-tomcat-7.0.33/logs/catalina.out in the first one then move the second terminal and type bin/startup.sh I got this /server/apache-tomcat-7.0.33/logs/catalina.sh : line 389 : /usr/bin/java/bin/java : Not a directory I changed JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk, it didn’t work
3 Answers 3
export JAVA_HOME=/usr should do it. The script runs $JAVA_HOME/bin/java
Thank you! It finally worked but now I have another problem if I type localhost.com:8080 , I get server not found. If I type 127.0.0.1:8080 , the Apache software foundation page displays. This computer isn’t connected to the internet.
that won’t work then. localhost.com is not your machine, it’s a real domain. You probably want to access localhost:8080
Just out of curiosity, if i want it to work locally will all I need to do is set up a dns? I don’t care if it’s localhost.com or anything else. I’m just curious as to how the setup of .com domain will work.
The strictly correct answer is this:
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk
The issue is that on a typical Linux system you access the java command (etc) via symbolic links that are created / managed by the alternatives command. This allows you to make a system-wide choice over which of the java installations should be used by default; i.e. via commands in /usr/bin .
The second issue this that the JAVA_HOME environment variable should point at the Java installation directory. The «bin» directory is a subdirectory of the installation directory. (Look at the contents of «/usr/lib/jvm/jre-1.6.0-openjdk» !!)
While export JAVA_HOME=/usr/bin will work for locating the commands, it won’t work if the Java application needs to find other files in the installation; e.g. the «rt.jar» file.
This «fine distinction» possibly doesn’t matter for Tomcat, but it is likely to matter for other Java software that uses the JAVA_HOME convention.
Footnote: if you are using an Oracle Java for Linux installation, the default installation directory will be a subdirectory «/usr/java». Sadly, the Oracle installer doesn’t understand that Linux «alternatives» system. You either have to register the alternatives for each of the Java commands by hand (tedious!!) or add the installation’s «bin» directory to your PATH.