javac cannot be run, and furthermore does not seem installed - java

I have a problem involving setting up Java.
I have installed the JRE, added its path to PATH, and set JAVA_HOME and CLASSPATH. Now, java and javacpl work fine, but running javac generates a command-not-found error. Furthermore, javac.exe does not even seem to exist in the JRE's bin folder.
How do I run javac?

The JRE is merely the Java Runtime Environment, which includes only the infrastructure needed to run Java programs that are already compiled.
To compile Java source code using javac, you need the Java Development Kit (JDK).
On Oracle's Java download page, choose the package labelled "JDK".

In order to use javac in cmd , JDK must be installed in your system...
javac will not work if you are pointing "bin" folder inside JRE (C:\Program Files\Java**jre7**\bin)
Please check for javac.exe inside your bin folder(C:\Program Files\Java**jdk1.7.0_45**\bin)
javac.exe must be inside JDK(C:\Program Files\Java\jdk1.7.0_45\bin) not inside JRE (C:\Program Files (x86)\Java\jre7\bin) "JRE doesn't come with a compiler. It is simply a java runtime environment. What you need is the developmental kit." in order to use compiler javac
For javac path(Points to remember while setting system env variable)
path = C:\Program Files (x86)\Java\jre7\bin this is wrong
path = C:\Program Files\Java\jdk1.7.0_45\bin this is correct
Make sure "javac.exe" must be inside your "C:\Program Files\Java\jdk1.7.0_45\bin"
Dont confuse with JRE and JDK both are totally different
if you dont have JDK pls download from this link http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
reference thread for JDK VS JRE What is the difference between JDK and JRE?
Procedure:-
Install JDK
open cmd prompt
type "cd C:\Program Files\Java\jdk1.7.0_45\bin " press enter(path may change based on jdk version and 32bit and 64bit os version)
type "javac" press enter
its done
Now go and change your system environment variable
path = C:\Program Files\Java\jdk1.7.0_45\bin
this will set the path permanently

The JRE doesn't have javac - you need to download the JDK (Java Development Kit).

First, you need to install the jdk, then add the path of bin folder of jdk in the path vaiable.
you can refer to this link

Related

How to run jar files in Mac using JRE?

Mac OSX 10.11.14 (El Capatin) does not ship with Java, either the complete development kit (JDK) or the run-time environment (JRE). My need was to just run a .jar file and not for complete Java development. So I downloaded the JRE from here, which is a much smaller file compared to JDK (quite obviously).
This SO answer says that JRE is enough to run jar files.
After installation of JRE I couldn't locate the directory where installation happened or run java command to execute files on my mac. How do I run jar files now?
To run java application you can either use
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
or (as you found)
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
In any case, if you need to run java often, you should set JAVA_HOME in either your ~/.bash_profile or ~/.profile and amend the PATH to include the bin directory.
After JRE installation, the correct path is:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin
But now, how do I run the java command? It seems like the java file located in the directory above is not an executable.

Finding JDK inside java installation folder on a linux machine

I have been told that in a Linux machine java along with jdk has been installed in /usr/java path.
But when I go to /usr/java/ i could so many files along with folder named bin,JRE. I want to know where is jdk installed here? Is bin folder itself is jdk?
My ls output for openjdk7 looks like this:
ASSEMBLY_EXCEPTION docs jre man THIRD_PARTY_README
bin include lib src.zip
The jre folder contains the JRE, the other files are part of the JDK, and not necessary for running Java applications which need only a JRE (e.g. the javac compiler in bin).
Open terminal and type " Which java " this will return JDK installation path
I guess you just installed the JDK under /usr/java. Try run ls /usr/java/bin, if java and javac is in /usr/java/bin, we can conclude that the /usr/java folder IS the JDK folder itself.

Error in setting JAVA_HOME

I have recently downloaded Maven and followed the instructions given on this this page. I already have ant installed on my machine.
Now, if I want to verify that Maven is installed perfectly or not it is giving me error that JAVA_HOME is not set correctly, but same works perfectly fine for ANT.
For Maven I tried :
1. open cmd
2. type mvn -version
3. Error appeared :
C:\Users\Admin>mvn -version
ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jre7\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation
For ANT I tried and worked :
1. open cmd
2. type mvn -version
3. Apache Ant(TM) version 1.9.1 compiled on May 15 2013
I went to the directory to check that java.exe is actually there in that directory or not and it was there. I checked the environment variables they set fine. I restarted the system and checked again but same problem. Please let me know what am I missing.
JAVA_HOME should point to jdk directory and not to jre directory. Also JAVA_HOME should point to the home jdk directory and not to jdk/bin directory.
Assuming that you have JDK installed in your program files directory then you need to set the JAVA_HOME like this:
JAVA_HOME="C:\Program Files\Java\jdkxxx"
xxx is the jdk version
Follow this link to learn more about setting JAVA_HOME:
http://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/index.html
Do not include bin in your JAVA_HOME env variable
Follow the instruction in here.
JAVA_HOMEshould be like this
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_07
JAVA_HOME = C:\Program Files\Java\jdk(JDK version number)
Example: C:\Program Files\Java\jdk-10
And then restart you command prompt it works.
Just remember to add quotes into the path if you have a space in your path to java home.
C:\Program Files\java\javaxxx\ doesn't work
but
"C:\Program Files\java\javaxxx\" does.
The JAVA_HOME should point to the JDK home rather than the JRE home if you are going to be compiling stuff, likewise - I would try and install the JDK in a directory that doesn't include a space. Even if this is not your problem now, it can cause problems in the future!
You are pointing your JAVA_HOME to the JRE which is the Java Runtime Environment. The runtime environment doesn't have a java compiler in its bin folder.
You should download the JDK which is the Java Development Kit. Once you've installed that, you can see in your bin folder that there's a file called javac.exe. That's your compiler.
JAVA_HOME should point to jdk directory like in the image with new variable, like below
PATH should point to jdk bin like below
Run the below command in your terminal and restart it.
> set JAVA_HOME="C:\Program Files\Java\jdk-xx.xx"
xx.xx is the java version

How to set path for Jre 6 when jre 7 installed?

I am programming through java 1.6 u_17, but i have JRE version 6 and JRE version 7 installed, so how to run my compiled program from JDK 1.6 to run through the JRE 6 only?
By Default, it runs my class files through JRE 7, how to change this behavior? Any idea of setting Class path in windows 7, as we does it for JDK.
The following is shown in my command prompt
E:\JAVA>javac -version
javac 1.6.0_17
E:\JAVA>java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)
This is for my SET command showing the Windows 7 environment paths
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Administrator\AppData\Roaming
ClassPath=C:\Program Files\Java\jdk1.6.0_17\bin\mysql-connector-java-5.1.5-bin.jar;
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=RANDMATE-PC
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Administrator
JAVA_HOME=C:\Program Files\Java\jre6\bin;
LOCALAPPDATA=C:\Users\Administrator\AppData\Local
LOGONSERVER=\\RANDMATE-PC
NUMBER_OF_PROCESSORS=2
OS=Windows_NT Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_17\bin;C:\Program Files\Java\jre6\bin;C:\Program Files\MyS
QL\MySQL Server 5.1\bin;C:\Program Files\UltraEdit\;C:\Program Files\Jar2Exe Wizard\;C:\Program Files\Java\jre6\bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 6 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0605
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\ADMINI~1\AppData\Local\Temp
TMP=C:\Users\ADMINI~1\AppData\Local\Temp
USERDOMAIN=RANDMATE-PC
USERNAME=Administrator
USERPROFILE=C:\Users\Administrator
windir=C:\Windows
Looks like you are using Windows. Please go the Environment Variables and define a user variable as:
Right Click(My Computers) -> Advanced -> Environment Variables -> Add
Variable Name = JAVA_HOME
Variable Value = Root Folder of Java 1.6.0_17 installation
Also in the same screen, please check the PATH variable and make sure **bin** Folder of Java 1.6.0_17 installation is added in the path preferably in the beginning and remove the Java 7 from the path, if it is there.
I fix this problem by removing the java.exe in system32 folder. And then in the cmd the java command refer to the jdk set in the path enviroment variable.
java.exe is also available in C:\windows\system32 and in your case its version might be 1.7..
Since your path has C:\windows\system32 first. no matter how to set rest of the path, sonar always will load jre7. (refer to conf\wrapper.conf in Sonar directory, by default it has wrapper.java.command=java)
To fix this, change following property of the "wrapper.conf" file
wrapper.java.command=C:\Program Files\Java\jdk1.6.0_XX\bin\java
this will fix the issue irrespective of the path variables.
For those who had the same problem I suggest reading this thread:
https://superuser.com/questions/479889/wrong-java-version-being-reported
Quote of wmz: "To check what actually executes when you run 'java -version' run from command line:
for %I in (java.exe) do #echo %~$PATH:I"
Windows is checking the PATH variable to find an executable named java and using that to launch your application. It is quite normal in a development environment to have many installations (as you do). However this calls on you to manage your environment.
There are two ways for you to set environment variables in Windows. By going to My Computer > Advanced Settings > Environment Variables as described above, you can set a variabler to your JDK installation and then update the Path to find the bin directory in that installation. Youy have the choice of updating System variables (all users) or user variables (your account only).
Personally, I prefer not to use the system/user environment variables as this provides less flexibility. You can use bat files to explicitly set the Path for a specific moment in time, or indeed to override the JAVA_HOME to point to a different installation.
If you are using an IDE you can usually specify the target runtime on a per project basis. Alternatively, when running the program, provide the fully qualified path to the version of the java executable you wish to use.
I had same problem. Issue is that Java installation will copy a java.exe, javaw.exe and javaws.exe to windows/system32 directory. You must have installed JDK7 recently.
I just removed those files from Windows/System32 directory, however, kept older version in path. This solved the issue.
Try it out.
I was facing the similar problem. I am using Java 7 and Java 8 together. The Java 8 was installed in the machine but the 7 set-up I copied from another system. I have already set the JAVA_HOME & path pointing to 7. But when I try to echo %path%, it shows the Jdk 8 in the class path. after lots of google, I have found "C:\ProgramData\Oracle\Java\javapath" in the path. Removing the line from the path solved the problem.
Background
I'm using Windows 8.1 and I have both JDK6 and JDK8 installed. For development purpose, I needed to get java version "1.6.0_45" over the command java -version and javac 1.6.0_45 over javac -version. The second command was working as expected after setting JAVA_HOME as Home folder of JDK6 and adding %JAVA_HOME/bin% in Path. However the first command was still returning java version "1.8.0_71"
Troubleshooting
I could find the an entry in the Path environment variable which points to C:\ProgramData\Oracle\Java. This folder actually contains short cut to java.exe of JDK8.
Proper solution: Uninstall JDK 8
Workaround:Edit the short cut file so that it points towards java.exe inside %JAVA_HOME%\bin (Please replace the variable with actual folder)
set the PATH variable to your jdk6\bin directory. so that it will pick the javac and java from jdk6.
for setting the path variable go to Environment Variables.
After setting the path variables you need to restart your command prompt. (NOT the computer).
Just right click on MyComputer, then Advanced System Settings-->Environment Variables-->New
Then in the "variable Name" text field add the string "PATH" or if it already exists select PATH from the list and click edit then append the path for "bin" folder in java in program files to the Variable value text field followed by a semicolon (;), if not exits add the path of bin directory of your java folder in "Variable Value" field and click "OK".
If you want to check the result, open up a command prompt and type "java" then hit enter.
For windows 7(X86) path setting:
first step:
Mycomputer(Right click)-->properties-->advanced settings-->environment variales-->new
(user variable)
on this first varible name: "" JAVA_HOME "" value: "" C:\Program Files\Java\jdk1.7.0_45 ""
second variable name: "" PATH "" value: "" C:\Program Files\Java\jdk1.7.0_45\bin;.; ""
There are two types of path for java : Permanent & Temporary.
Here is the video tutorial describing how to set path for Java?
How to Set path for Java : https://www.youtube.com/watch?v=rM4Qq3Ua7Sk
This video tutorial will guide you in setting permanent and temporary path for Java. Simply follow the steps. This will work with any version of Java, JDK or JRE. In video I have used path of JDK, Simply copy path of JRE instead of JDK and rest is same.
OR read the tutorial here : How to Set path for Java : http://aatul.me/2011/08/24/how-to-set-path-for-java/
Hope this solutions will help you.

Why does java -version return an old version?

OS: Windows XP
I am using yuicompressor-2.4.2 to compress some CSS before uploading to my server.
But when I run it, the following exception appears:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/yahoo/platform/yui/compressor/Bootstrap (Unsupported major.minor version 48.0)
So I think it's because of the JRE.
I typed in the command:
cmd: java -version
And it says:
java version "1.3.1_01"
But it should say 1.6.0_16, since I have installed the latest version.
What should I do to make Java use the latest version instead of the old one?
Set the environment variable JAVA_HOME pointing to the directory where you have jdk 1.6.0
set JAVA_HOME=your_path_to_jdk1.6
set PATH=%JAVA_HOME%/bin;.;..;%PATH%
That's from a command window. Also you can do it from "My PC > Properties > Advanced > Environment variables"
Go to the system32 directory C:\Windows\System32 and delete following 3 files
java.exe
javaw.exe
javaws.exe
Now create a JAVA_HOME environment variable with value={root path of your jdk installation} and add the path till bin folder of your jdk in the PATH environment variable.
Open a fresh command prompt and run java -version to confirm the change
If you are using windows 7/10 go to command prompt and type
where java
Delete all the symbolic link shows below other than your actual installation directory.
Even if correctly added all the environment variables still sometime you can get wrong versions especially when you have multiple version installed in your system and want to switch between them.
On Windows, the JRE installs a java executable in the Windows directory, which should be the first java in your path. This is just a wrapper that looks in the Windows Registry to find the Java home directory (should be "%SystemDrive%\Program Files\Java\jre6" for Java 6) and runs using the libraries there.
Run %SystemRoot%\system32\java -version and see what you get. If that is Java 6, you have entries in your path before %SystemRoot%\system32 (which really should be first). Either fix your %PATH% variable, or you'll have to be explicit whenever you want to run this version of Java.
If running that instance of java doesn't report Java 6, its not installed (correctly). Uninstall and try installing again.
If you are having trouble because of the PATH, it is because you or some software you installed monkeyed with it; I recommend using the default which is to have system32 first. Everything works fine if the defaults are used.
Also, %JAVA_HOME% is not used by the JRE itself at all. Some common Java applications like tomcat and ant honor the %JAVA_HOME% setting, so perhaps yuicompressor does too. But this is a de facto convention, not a standard.
after where java in Command prompt
for example
where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe
delete C:\Program Files\Common Files\Oracle folder
then close all terminals and write java -version in the terminal. it will show the right version
worked for me
You should modify your PATH environment variable:
My PC > Right click > properties > Advanced > Environment variables
And modify "Path"
Append at the end the path to your 1.6 installation:
;C:\jdk1.6.xxx\bin
and remove the previous one if present.
Add %JAVA_HOME%/bin to your PATH environment variable where JAVA_HOME is set to your JRE6u16 directory
I had the same problem. In System Properties > Environment Variables > System Variables > PATH make sure there is no other path associated with Java. To make sure, type in and check Java paths.
where java
Re-open Command Prompt and type java -version again. I hope this helps.
first by the following command, you should be aware of .exe file which runs when you type java in the command prompt
where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe
as you see above , cmd first reads java from
C:\Program Files\Common Files\Oracle\Java\javapath
so go to the path above and remove java files .
then it should work fine
You should check your PATH environment variable. It is possible that some application you have installed has put its version of the jre in front of yours in the path.
It looks like the older Java version is still on the system PATH environment variable (where the OS looks for commands) or JAVA_HOME (where yuicompressor may look for the java executable)
How those variables are changed depends on your operating system.

Categories