I am working on a simple java editor that uses ant to call JDK.
On eclipse everything work fine, I am able to build build.xml. The problems is when I export my Editor to an executable jar, and I try to build the build.xml of a project, I get the famous problems:
Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files (x86)\Java\jre7"
Important:
If i run my jar Editor from cmd it's work fine ,but if i double click the Editor jar it doesn't work , i get the famous problem (unable to find javac compiler...).
Notice:
JAVA_HOME points to the JDK.
I am using ant.jar and ant-launcher.jar.
Eclipse points to my JDK installation.
tools.jar is added to JDK/lib folder
the solution is to set fork attribute to yes on javac target .
Perhaps JAVA_HOME does not point to the JDK.
JAVA_HOME is currently set to C:\Program Files (x86)\Java\ jre7
The message is fairly informative and to the point, is it not?
Your JAVA_HOME looks like it is pointing to a JRE installation, not a JDK installation. (The error message says it is "C:\Program Files (x86)\Java\jre7"!)
A JRE does not include any of the Java development tools ... such as the javac Java compiler that Ant is trying to load / use.
If you really have a JDK installation on your machine, then all you need to do is to change the JAVA_HOME environment variable so that it refers to it ... instead of the JRE. Otherwise, you also need to download and install the relevant JRE.
Related
I am trying to install JBOSS BPM Suite but get this error. I have looked around the web for a solution but did not find anything that really explains how to resolve this. I have JBOSS EAP 7 installed but have no idea how to set the 'jar' binary in PATH.
What you need to do is install the JDK and include the bin folder of JDK in your Path system variable.
See: No ‘jar’ binary detected in PATH
Run it from the bin folder of JDK.
e.g. C:\Program Files\Java\jdk1.8.0_131\bin>java -Dizpack.mode=privileged -jar D:\BPM\jboss-bpmsuite-installer-6.2.0.BZ-1299002.jar
I had the same issue. My issue was resolved by adding the additional java components on top of the included openjdk in RHEL:
yum install java-devel
When I try to compile a .java file, it says "Command javac not found."
I've done a fresh install of Java using an installer downloaded from their website. I've tried the solution on all of the other posts that says to check my path, but it already includes "C:\Program Files (x86)\Java\jre1.8.0_73\bin;" which contains which looks like a ton of utilities - except, there's no javac executable.
I searched my C drive with File Explorer, and couldn't find it anywhere. I've installed and reinstalled, so I think I might just be looking for the wrong thing to compile my programs. Please help!
You have installed the java jre. You need to install the jdk.
The jre (java runtime environment) contains the files needed to run java.
The jdk (java development kit) includes the jre and also all the development utilities.
Go to the download page, and select the jdk.
I had the same problem and with jdk-8u73-windows-i586.exe from the Oracle downloads page - it installed a JRE and no JDK. Solved the issue by downloading jdk-8u74-windows-x64.exe, which installed both a JRE and a JDK.
I am trying to run java application and I am getting following error,
Unable to find a javac compiler; com.sun.tools.javac.Main is not on
the classpath. Perhaps JAVA_HOME does not point to the JDK
I have gone through many SO questions and found solution is JAVA_HOME should be point to JDK, not JRE.
Then I have tried to print JAVA_HOME in command prompt,
I had set this JAVA_HOME from my computer->properties->env variables -> system vars as below,
I had also added new variable in eclipse using preferences as,
And finally I am still getting the same error. Whats wrong with JAVA_HOME ?
Update :
In eclipse-preferences-installed jres there is only one entry is present and which is jdk and selected,
And under project properties java build path-libraries there is JRE System Liberary [jdk1.8.0_31] is used.
Update 1 :
C:\Program Files\Java\jdk1.8.0_31 have folder named jre. Is that jre folder causing this issue ? Can I remove this folder ? Is there is any way to add only jdk liberary in project ?
Eclipse is an IDE and as such, it has (at least) two Java versions: The one which it uses itself to run (JAVA_HOME) and a JVM which it uses to run your application. The two don't need to be the same.
So to fix your problem, you need to look into Eclipse's preferences, specifically Installed JREs which gives you a list of Java VMs which Eclipse will use to run Java code from projects. My guess is that there will be several entries there and the default will be a JRE instead of a JDK.
Make sure you have a JDK in the list and then go to your project. In the project, you can select which Java VM to use under Java Build Path -> Libraries.
[EDIT]
Look closely at the last screenshot: You've configured Eclipse to use C:\Program Files\Java\jdk1.8.0_31\jre which means you've pointed it at the JRE inside of the JDK. Use C:\Program Files\Java\jdk1.8.0_31 instead (without the \jre at the end).
[EDIT 2] If you delete the jre folder, Java will stop working. Any JDK also contains a JRE. The JRE contains rt.jar with String.class and the like. The Java compiler is in tools.jar which is in the JDK.
If recreating the JRE entry in Eclipse doesn't help, you'll have to add it manually to the classpath.
You can use a variable ("Add Variable...") to make sure Eclipse updates the path when you switch to a new/different JRE. Try JAVA_HOME with the extension lib/tools.jar
In Eclipse click Run->External Tools->External Tools Configurations
Click JRE tab
Click Installed JREs... button
Click Add button (select Standard VM, where applicable)
Click Directory Button
Browse to your JDK version (not JRE) of your installed Java (eg: C:\Program Files\Java\jdk1.7.0_04)
Click Finish.
Re-run Ant script - have fun!
I faced the same issue while i was using ant from command prompt and the solution which I found is that you need to put tools.jar inside bin folder which is present inside apache ant folder.
For eg :-
D:\apache-ant-1.10.12-bin\lib
You will get tools.jar inside
C:\Program Files\Java\jdk1.8.0_211\lib
Please change the path based on your java installation path.
According to the Eclipse FAQ. I read that
Eclipse DOES NOT consult the JAVA_HOME environment variable.
My doubt is how does eclipse initializes the Virtual Machine. It does not know the location of Java. My eclipse.ini file does not have -vm configuration. Still I am able to run eclipse.
The Source
UPDATE
According to Eclipse Installation Guide. Eclipse does not write entries to the Windows registry.
As far as I know, to invoke the JVM, Eclipse executes the java command, so, if it's at your system execution path, Eclipse won't need to find the instalation directory.
To check, you can start a OS shell and execute the next command (from any location):
> java -version
EDIT: I was (partially) wrong. From the FAQ (http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#Find_the_JVM)
If a JVM is installed in the eclipse/jre directory, Eclipse will use
it; otherwise the launcher will consult the eclipse.ini file and the
system path variable
So, Eclipse first looks inside its eclipse/jre dir for installed VMs, if empty, consults the eclipse.ini file, and at last, looks at the system path.
Even Help->Installation details->Configuration would give you the exact version and type of jvm you are using . Here it is clearly given in System Properties
Eclipse will run using whatever version of JRE you have installed. To see/edit the version being used, go to Preferences -> Java -> Installed JREs
Or just run a java program in Eclipse. Eclipse will show the full path of javaw command it is using.
Eclipse looks for system Path variable to get the installed JVM. It depends upon how you have defined path variable. Order in which several versions have been defined in path does matter i.e. if jdk1.5/bin is set before jdk1.6/bin, system will pick 1.5 version when you execute java -version on cmd
Solved!
1) downloaded and installed 64-bit versions of both the ADT for Android (Eclipse) and JDK Java bundle
2)updated the PATH environmental variables (Win Control panel...System...advanced opt...Envir.variables)
In my case it now looks like this:
C:\Program\Java\jre7\bin\client\jvm.dll;C:\Program\Java\jdk1.7.0_21\bin
(no backslash after the \bin directory)
These days on WIN64, oracle creates a couple of new directories and adds them to your path. The one eclipse will default to is the second directory you specify in the installation process, because that gets loaded at the head of the path ahead of your JAVA_HOME. It is confusing why they ask you for two directories, I have no answer for that. I blew away the second directory, removed the two added directories from the path, configure my JAVA_HOME environment variable (in my case already on the path pointing to an older version) accordingly, and eclipse is good to go.
In eclipse, the installed JREs having only JDK1.6 and nothing else. But on building the project using gradle, i'm getting the following error.
Caused by: : Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files (x86)\Java\jre7"
I found some solutions over net the the ant might not have the "tools.jar". I tried adding "tools.jar" to the Global Entries of Ant runtime environment. But still the problem exists.
Can anyone help me fix this ?
The error message is quite clear: JAVA_HOME doesn't point to a JDK. Set the JAVA_HOME environment variable to point to a JDK, and not a JRE.
Why do you think changing the environment of the ant runtime would have any impact on Gradle?
If not JAVA_HOME then probably You have project structure issue. By default, Gradle will look for sources under src/main/java/. If you put your sources somewhere else than this message could happen. First check your JAVA_HOME path if its set to JDK (not JRE!) then check your project structure.