When i am running Jenkins which checks out code from a repository and perform mvn package or some command. I get this error:
Unable to locate the Javac Compiler in: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.
My JAVA_HOME points at jdk location only.Still it looks at
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/tools.jar
for the compiler.Why is that???
It seems the problem is with the code ..It points to /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/ for the tools.jar,whereas it needs to look into the /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/lib/ where the jar is present.I tried copying the jar to jre /lib/ but to no avail.Any solutions for this...
Thanks for d answers anyway..
You need jdk (java development kit) to compile java programs. jre only use to run compiled java programs. in your case its point to a jre and thats why you are getting this.
you can download the jdk and install.
you can download jdk rpm from here
http://www.oracle.com/technetwork/java/javase/downloads/jdk7u9-downloads-1859576.html
use this to choose java alternative if you have already installed.
/usr/sbin/alternatives --config java
Uninstall the installed JRE. Keep only one JAVA defined by JAVA_HOME and define your lib and classpath with respect to JAVA_HOME.
Related
There are many similar questions but mine is different so please read an entire question before nailing down the new.
Bundled JAVA jdk is automatically installed with Android Studio version 4.0.1. Everything I type java -version on my CMD then I get following message
C:\Users\OceanicBlue>java -version
'java' is not recognized as an internal or external command,
This is because JAVA_HOME is not setup so I tried following inside Environment Variables->System Variables in Windows 10 Machine but no luck. The problem is persistent.
JAVA_HOME -> C:\Program Files\Android\Android Studio\jre\
JAVA_HOME -> C:\Program Files\Android\Android Studio\jre\bin
JAVA_HOME -> C:\Program Files\Android\Android Studio\jre\jre\bin
JAVA_HOME -> %JAVA_HOME%\bin
Can I use Android's bundled JDK for JAVA_HOME? If not then which version should I download. Oracle forces you to register to use their JDK11. I refuse to give them my personal information to use something free. Also I don't want unnecessary extra versions of JAVA installed on my machine. Eventually they will cause problems.
What exactly am I trying to do? I am trying to compile Java programs using Command line. Android installed JDK for me so why not use it? No I am not able to compile a java project using the terminal screen inside Android Studio.
This is because JAVA_HOME is not setup
That's not what's happening. JAVA_HOME is not voodoo magic, the windows shell does not have some sort of built in knowledge. Commands entered are executed by scanning every entry in the PATH environment variable for java.exe, java.com, or java.bat. None are available. If you really want the java.exe found in C:\Program Files\Android\Android Studio\jre\bin to be used when you type 'java' on the command line (which will not magically make javac work at all, which is why I doubt this is actually want), then add that directory to the PATH variable. JAVA_HOME is mostly useless; a select few dated tools look at it sometimes and fail if it is not there; more modern tools may still look at it but also scan other places, such as the path or windows registry.
Furthermore, that's.. clearly not a bundled JDK, that's a bundled JRE, which can't be used for compiling. It does hava java.exe, but you can't use that to compile things. By nature of being a JRE, it is also obsolete/outdated (JREs are no longer part of how java is distributed; java8 is the last version with a JRE).
Note that javac in general is relatively useless when dealing with android; android does not run class files.
I am using Android Studio 4.1.1
What exactly am I trying to do? I am trying to compile Java programs using Command line. Android installed JDK for me so why not use it?
First of all, it is just the bundled JRE. Its is not JDK.
But, I was able to compile and run my test.java by adding two new entries in my environment variables.
C:\Program Files\Android\Android Studio\jre\jre\bin
C:\Program Files\Android\Android Studio\jre\bin
NB: I have never installed JDK before. I just used the JRE binaries present in jre/bin/ present within Android Studio folder
See the attached image.
I think you should recheck your environment variable or else try to get Android Studio latest release.
I just updated to IntelliJ IDEA 16 which comes with Java JDK 1.8. Fyi, I had downloaded Java JDK 1.8 a long time ago.
I tried to run my plugin that I am developing, and I cannot even do that, I get the following error message (slightly condensed)
"C:\Program Files\Java\jdk1.7.0_45\bin\java" -Xmx512m -Xms256m -XX:MaxPermSize=250m -ea "-Xbootclasspath/a:C:/Program Files (x86)/JetBrains/IntelliJ IDEA Community Edition 144.3143.6\lib\boot.jar" -Didea.config.path=C:\Users\Christopher.IdeaIC14\system\plugins-sandbox\config - ... -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.7.0_45\lib\tools.jar; ... ;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 144.3143.6\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.intellij.idea.Main
Unsupported Java Version: Cannot start under Java 1.7.0_45-b18: Java 1.8 or later is required.
So, I clearly know what the problem is; however, I cannot seem to figure out where the location to fix this is.
I have tried a lot of things so far; most involve using the search box in Settings and switching whatever I could to version 1.8. Also, I had updated my Environment Variable for Java from 1.6 to 1.8
With all of these changes, nothing is working! So how do I go about fixing this seemingly simple issue?
Set IDEA_JDK (or IDEA_JDK_64) environment variable.
Check Selecting the JDK version the IDE will run under
TL;DR --> Set JAVA_HOME to C:\Program Files\Java\jdk1.8.0_51
Java 8 is required to run IntelliJ IDEA starting from version 16 on all the supported platforms.
The actual JDK version used by the IDE can be verified in Help | About dialog (open any project to access the menu).
idea64.exe uses this JDK search in the following sequence:
IDEA_JDK_64 environment variable
..\jre64 directory
system Registry
JDK_HOME environment variable
JAVA_HOME environment variable
Under Arch Linux you can simply set java 8 as default (you must have it installed):
$ sudo archlinux-java set java-8-openjdk
In case anyone arrives here and hasn't had any luck with the other solutions, try this. I'm using PhpStorm under OSX, but the steps are probably applicable to JetBrains' other IDEs too:
Navigate to your IDE's config folder (see this article to learn how to find this folder's location).
Open the idea.propeties file.
If a JVMVersion attribute exists, delete that entire entry. If it doesn't exist, then this probably won't be of much help!
Save the file.
Launch your IDE.
Just set JAVA_HOME system variable to your JDK 8:
Run in cmd
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_111"
don't foget to change to your java path
In my case, Ubuntu 14 (32-bit), I opened the file:
/home/<user>/Programs/PhpStorm/bin/phpstorm.sh
and after
if [ "$JDK" = "" ] && [ "$OS_TYPE" = "Linux" ] && ........... fi
I added:
if [ "$JDK" = "" ]; then
JDK="/usr/lib/jvm/java-8-oracle"
fi
And then it works!
Double check that your JAVA_HOME points to the correct 1.8 Installation and make sure that in the PATH env there is no reference to "C:\Program Files\Java\jdk1.7.0_45\bin".
Try to print your JAVA_HOME/PATH from the Console and see what the output is. If your changes are not reflected logout and then login again.
IntelliJ 16 REQUIRES Java 8 to run, it won't run under Java 7. It's compiled to Java 8 classes so it can't ever be run on an older JVM.
This is well and clearly mentioned in the documentation.
So if you have your system JVM be an older one, it will fail to start unless you coerce it into using a non-default JVM.
Possibly you have some java related executables left over in your Windows/System32 directory, where some older Java installers would drop them. Delete these by hand from the file system and see what happens.
Just in case this page needs one more recommendation, I fixed the problem in my case by going to the IDE's config folder (as #Nate puts it, see here for how to locate it), and deleting the idea.jdk file (which held a reference to a 1.6 VM).
Apart from setting the correct Java version for the global, per project and per module SDK, for the Java Compiler, and for the language level, you also must set the Target bytecode version both for the project and (if you use maven) for each maven module.
Often the project bytecode version is correct but the module bytecode version is lower, i.e. 1.5.
The per-module bytecode version is not displayed when opening the default preferences via File > Other Settings > Default Settings. You must edit the current preferences either via a shortcut (i.e. ⌘+,) or from the main menu as shown below (for mac):
I had the same problem. All paths pointing to java jdk 8, but still throwing the error. I was able to run Android Studio by running the "studio64.exe" instead "studio.exe" in the bin folder
I have multiple versions of Java installed in the environment(I know it is bad). I've set the JAVA_HOME to jdk 1_4 directory. This is not installed, but extracted from zip and placed it somewhere. We have java 1.8 JRE also installed in the system. I never set the path to this installed directory. Now i'm trying to run some ant script that depends on jdk 1_4. I get some exception saying that it is not able to find tools.jar in java1.8... .
My question is that when the path and java_home are set to jdk 14 why does the ant look for 1.8 version of java? I'm confused.
Update: I have looked up the duplicate issue.
Additional details: Java -version prints 1.8 with jdk 14 in the path and java_home. I uninstalled 1.8. reopened cmd tried java -version, now it errors out saying that it is not able to find java1.8 instead of trying to find the next java available in the path or java_home.
Error shown:
C:\Users\usrpao>java
Error: could not open `C:\Program Files\Java\jre8\lib\amd64\jvm.cfg'
I have multiple versions of Java installed in the environment(I know it is bad). I've set the JAVA_HOME to jdk 1_4 directory.
Not wrong at all. I have a similar setup because I have to switch between Java version.
First, install Java JDKs in the root of your drive. No spaces in the directory names. For example, C:\Java\Java-1.6-21 and C:\Java\Java-1.7-5.
In your Environment Variables section in your System Control Panel (under Advance), create an environment variable to point to each one of these Java Home directories. For example, JAVA_HOME_17 = C:\Java\Java-1.7.5 and JAVA_HOME_16 = C:\Java\Java-1.6-21. This should be a System Environment variable.
Create a JAVA_HOME environment variable that points to the Java version you want: JAVA_HOME = %JAVA_HOME_17%.
Now in the System PATH, prefix the PATH (the very first entry) with %JAVA_HOME%\bin.
When you open a console window, your default java and javac commands will be the correct Java version.
If you need to change a version, change the JAVA_HOME environment variable to point to the correct environment variable and open a new console window. Now that new Java will be in your path.
NOTE: It is vitally important that %JAVA_HOME%\bin is in the first part of your PATH before C:\Windows\System32. You don't want the java.exe that exists in that directory to be your default java.
You haven't specified the operating system, so:
on windows, java installs a java.exe in C:\Windows\system32, which is probably on the path before java_home, and so gets picked up
on Linux, various distributions that support multiple installed java versions will also have some symlink earlier on the path. Run 'which java' to determine where that symlink is
Multiple java versions in the system is the problem, I uninstalled all the java versions first. Restarted my machine. Path and java home points to the jdk 1.4. java -version now points to the version specified in the path. Thanks all.
I am new in learning java programming! I want to make a .jar in a maven project. After running this command mvn clean install, I am getting the following error message:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile(default-compile) on project wps-demo: Compilation failure
Unable to locate the Javac Compiler in:C:\Program Files\Java\jre7..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and not a JRE(the com.sun.tools.javac.Main class is required)
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable
what can I do for clean this error!
It looks like you have only a JRE (Java Runtime Environment) installed, and not a JDK (Java Development Kit), as this error message says:
Please ensure you are using JDK 1.4 or above and not a JRE(the com.sun.tools.javac.Main class is required)
Download and install the JDK (not JRE) from Oracle's website.
The JRE allows you to run Java programs, but does not include the tools that you need to develop Java software, such as the Java compiler. The JDK does include those tools.
If you already have a JDK installed, then make sure that the JAVA_HOME environment variable refers to the directory where you have the JDK installed, and not to a directory with a JRE.
As your error says you have wrong value in JAVA_HOME variable in system settings... should be something like C:\Program Files\Java\jre6
You can find how to set it HERE for example.
You need to set the environment variable that specifies the location of your java development kit so that windows can find the Java libraries
Put java home path in a JAVA_HOME variable that you can create in the advanced tab of MyComputer properties.
The Java home path would look something like this
C:\Program Files\Java\jdk1.5
Hope this helps
You may also want to have a look at the following article from Maven http://maven.apache.org/guides/mini/guide-building-jdk14-on-jdk15.html
It states that from Maven 2.2.0, Java JDK 1.5 is needed to allow Maven to build the Java project. The article also goes on to show how some of these adjustments can be made so that JDK 1.5 or later can be used in the build process.
I'm using a Windows .bat script and I set JAVA_HOME as C:/Program Files/Java/jdk1.6.0_32
when I do a java -version, it still shows the 1.3
How can I fix this? What am I doing wrong?
For me the issue was in my PATH variable, C:\ProgramData\Oracle\Java\javapath; was added by java windows install before my %JAVA_HOME%\bin;.
So I'd echo %JAVA_HOME% pointing to a JDK7 and java -version showing jdk8.
I'd to put %JAVA_HOME%\bin; before C:\ProgramData\Oracle\Java\javapath; so that java -version displays jdk7.
Try %JAVA_HOME%\bin\java -version
If you modify JAVA_HOME, it's usually better to invoke java with an absolute path (using JAVA_HOME) because the new binary is probably not in the path (and then Windows will load the wrong binary).
Make sure that the PATH environment variable is pointing to %JAVA_HOME%\bin.
Be sure not to mix the system variable path and the user variable system path. I feel OK in calling java without the absolute path (when I know how JAVA_HOME and PATH are configured).
Calling java -version from command line, causes cmd.exe to do the lookup on the "known" directories. "Known" means PATH environment variable. It seems that your PATH contains a java 1.3 bin folder, and not 1.6.
JAVA_HOME is another variable, that is used (for example, and not only) by java wrappers, or by scripts executing some java stuff.
Try doing this:
SET JAVA_HOME=C:/Program Files/Java/jdk1.6.0_32
%JAVA_HOME%/bin/java -version
Add quotes where needed.
I had similar issue,in my case , I had two versions java installed. it can be fixed by uninstalling one version of java completely from system.
Had a similar scenario today - two Windows 10 devices - both have JRE 1.6 & 1.7.
When typing
Java -version
One device shows 1.6 the other 1.7.
This was preventing me running a third party JAR to install some software on the device showing 1.6 (which worked fine on the device showing 1.7 when running java -version), using:
java -jar ThirdParty.jar
As the JAR needed to be run by 1.7.
Cause of this was in the PATH environment variable - one device had the location of 1.6 first in the PATH list, moving the 1.7 location above the 1.6 location resulted in consistency using Java -version and allowed me to install the software.
java -version will consult the paths in the special environment variable Path. You need to select the java version you want and move it upwards the latter (click "Move Up"). You probably have that reference to JDK 1.3 in Path above your addition of JDK 1.6. Since that's the first thing the OS finds, that's what it chooses to run.
Executing the command again with the same window opened after changing the environment variables will not work. Re-open it
I know this question is old but this was my case and I wanted to re-explain further, similar to #DanBot 's case