"java" command is getting executed but not "javac" command [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
My question looks similar to java-comand-works-but-not-javac but its different from the way that I deliberately had removed java bin directory from "path" variable and "JAVA_HOME" so that "java" and "javac" shouldn't be executed without giving full path to "javac" or "java".But still "java" is getting executed. For "javac" it is throwing 'javac' is not recognized as an internal or external command,
operable program or batch file.
But for "java" it is showing C:\Users\Nandi_Gaurav>java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)
I want to know the reason. I am using "Windows-7" .

If the problem is that java running when you don't expect it to1, open up a cmd window and execute:
C:\USERS\Nandi_Gaurav\Documents>where java
C:\Windows\System32\java.exe
You'll almost certainly see that there's one installed in the Windows system directory.
That's why it's still executing even though you think you've removed it from the path.
If you really want to get rid of it, either delete it (assuming it's still available in the JRE/JDK directory) or rename it to something like nojava.exe.
Whatever you do, don't remove c:\windows\system32 from your path, that'll cause all sorts of issues :-)
1 Your problem may also be that javac is not running, in which case the JDK may not be installed. However, based on your question, that doesn't seem to be the issue - you're more concerned about things running when you've tried to disable them, rather than with things not running when they should be.

Java may be executed from the JRE that is installed in another path of your system.
Javac is part of the JDK, so you should install it, and set the appropriate paths.

You need to install Java Development Kit (JDK) which provides javac to compile your java code. You have the Java Runtime Environment (JRE) which is mainly for running java programs.
This question may help: javac : command not found

I think your 'Path'-variable is only used for javac.
Java-configuration in windows can be found here:
Explanation on java.com

Most probable issue could be that you are using JRE instead of JDK.
When you download java you can get it either as jre(Java Runtime Environment) or jdk(Java Development Kit) .
If you just want to run java programs on a machine , install JRE.
if you want to develop , compile and run a java program install JDK.
Both can be downloaded from oracle.Link for JDK 1.6
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR

Related

Java on PATH is ignored (Ubuntu/Bash) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
In Ubuntu I have added the following to my ~/.bashrc
export JAVA_HOME=/home/user/tools/jdk-11.0.4
export PATH=${PATH}:${JAVA_HOME}/bin
export PATH=/home/user/tools/apache-maven-3.6.1/bin:$PATH
But when I run (after a reboot):
$ which java
/usr/bin/java
$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~19.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
Why is it still picking up java 8 from /usr/bin/java?
The locations in the PATH environment variable are searched in order, and the first match for an executable is returned. Since you added JAVA_HOME at the end of the PATH, the global version of java is found first (as /usr/bin comes before JAVA_HOME).
Try this order instead (in the second line of your code above):
export PATH=${JAVA_HOME}/bin:${PATH}
BTW, it is not necessary to reboot each time you change ~/.bashrc. You can just open a new shell terminal.

how to upgrade my MAC OS X to use newer Java compiler? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
This is probably an easy question, but I could not find a clear answer to it by searching on stack overflow. I will delete this thread if its a duplicate. I am on a OS X Yosemite version 10.10.5, and my System.Preferences->java-> general shows that I have version 8 update 66 (build 1.8.0_66-b17). However some code fails due to use of old java compiler.
$javac -version (javac 1.6.0_65)
java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
How can I let my projects use the newest java compiler? (preferably as a systems default)?
After downloading the right jdk/jre #java.com, in your home directory (aka /home/<your name account>), add these lines to file .bash_profile (create file if don't exist and don't forget to replace <version> and change path if needed) :
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk<version>.jdk/Contents/Home
hope this will help you
Download the JDK from Oracle: http://www.oracle.com/technetwork/java/javase/downloads/ . Make sure you get the OSX version. It has its own installer so installation should be pretty straight forward.

Confusion about Java Versions

So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.

Which of these is my JDK path, and which is JAVA_HOME?

I just installed Linux Mint and am trying to configure SpringSource Tool Suite which requires you to direct it to the system "JDK path". Although I haven't explicitly downloaded/installed Java on this system yet, when I ran the update manager I did see Open JDK get installed and found several directories under /usr/lib/jvm (see screenshot below). My questions are:
Spring Tool Suite requires you to specify a path to the JDK, and my question is, which one do I choose, and why?; and
How do I tell which of these is my JAVA_HOME?; and
What's the difference between the "JDK path" and JAVA_HOME?
Thanks in advance!
Edit:
echo $PATH --> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
java -version -> java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)
which java -> /usr/bin/java
Spring Tool Suite requires you to specify a path to the JDK, and my question is, which one do I choose, and why?; and
This can only be answered according to the needs of your application. Do you need the stability of Java 6 or the features added in Java 7? Are there APIs you intend to use that are only available in Java 7 or are the Java 6 libraries sufficient? Do you have customers that require the use of one JVM over another? Only you can answer these questions.
How do I tell which of these is my JAVA_HOME?; and
You will want to make JAVA_HOME reference the specific JVM environment that you've decided on for your project. For example, if you decide on Java 6 you'll probably want to set your JAVA_HOME to /usr/lib/jvm/java-6-openjdk-amd64.
What's the difference between the "JDK path" and JAVA_HOME?
The JDK path refers to the Java Development Kit - which includes the java compiler, debugger and other tools associated with developing java programs. JAVA_HOME can reference either the JDK root or the JRE (Java Runtime Environment) root directory when running java programs; but you should, for development purposes, always have JAVA_HOME reference the JDK root.

Cannot create project in Eclim

Hello good people of Stack Overflow, I have come with yet another question for your bountiful knowledge to answer. I am having a problem using eclim, a program that integrates the features of eclipse for java development into the Vim editor.
I am unable to create a project using the syntax defined on eclim.org, which is this vim command, ":ProjectCreate /path/to/dir -n java". I am typing this like this, ":ProjectCreate /home/username/Java -n java", where username is my username. The error I get is,
Java Model Exception: Java Model Status [Java does not exist]
while executing command (port: 9091): -command project_create -f "/home/username/Java" -n java
This led me to test if Java was installed on my system, using java -version. The output is,
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.1) (6b22-1.10.1-0ubuntu1)
OpenJDK Server VM (build 20.0-b11, mixed mode)
So I had Java installed, and I believe that is the OpenJDK version that is not used in my eclim installation. The version I specified is Java 1.6.0_24 of the sun Java JDK. That's beside the point though, as I do have Java installed.
So that's what led me to you. One last thing I would like to add though. I am using a headless server to run the eclim server in the background. This is through Xvfb, and is also detailed on eclim.org. I don't believe that is causing the problem, but I just thought it would be handy to throw in. As always, thanks for the help that will doubtless be provided.
I have done further testing and my original comment was not the correct reason. The real problem, was that I already had a directory at ~/Java. That tried to execute that directory for the project, which it could not do.

Categories