java jre jdk setup using android bundled jre - java

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.

Related

Cordova android run/build Error - Requirements check failed for JDK 1.8

I have built my cordova app and getting "Requirements check failed for JDK 1.8" error message.
Uninstalling all java and installing jdk 1.8 not solved my problem.
D:\xampp\htdocs\aware>cordova run android
Android Studio project detected
ANDROID_HOME=C:\Users\Baha\AppData\Local\Android\Sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_221
Requirements check failed for JDK 1.8
ScreenShots:
You might have installed more than one Java (binaries) on your system. First of all, check this, by executing where java command in your cmd.exe (command line).
Most likely, you will see more than one java.exe installed, and if so, this may be the reason, despite installing new Java, your system still provides one more other version of it;
Even if you have set your %JAVA_HOME% environment variable accordingly, there might be another java.exe available in your environment, either because of having some other Java binaries' bin folder added in the System variables' (under Environment Variables) Path variable, or because of having it at some other place, which is also available through any other environment variable (for instance: System32 on Windows).
Check where java and see your Path environment variable under the System Variables.
My problem solved partially, I have changed the path and try to build with vs code, it works, but phpstorm still not build my app.

Unsupported Java Version: Cannot start under Java 1.7: Java 1.8 or later is required

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

Error while running a program on Android Studio

Error in android while trying to start Virtual Device Manager:
Cannot launch AVD manager.
Output:
"C:\PROGRA~2\Android\ANDROI~2\sdk\tools\lib\\find_java.exe" -s' is not recognized as an internal or external command,
operable program or batch file.
ERROR: No suitable Java found. In order to properly use the Android Developer
Tools, you need a suitable version of Java JDK installed on your system.
We recommend that you install the JDK version of JavaSE, available here:
http://www.oracle.com/technetwork/java/javase/downloads
If you already have Java installed, you can define the JAVA_HOME environment
variable in Control Panel / System / Avanced System Settings to point to the
JDK folder.
You can find the complete Android SDK requirements here:
http://developer.android.com/sdk/requirements.html
I have reinstalled java jdk several times, i have also set the JAVA_HOME variable correctly.
This problem also persisted in eclipse so i installed android studio.
Exact value of JAVA_HOME : "C:\Program Files\Java\jdk1.8.0_05\".
If any further detail is needed i 'll provide it in comments.
AFAIK, AndroidStudio generally looks out for JRE stuff and Eclipse looks out for JDK stuff. This is what I've done to make both Eclipse and AS work in my system:
Set 2 Environment Variables like below and see if it works..It worked for me without issues
JAVA_HOME - C:\Program Files\Java
JDK_HOME - C:\Program Files\Java\jre7
Hope this helps...

Java program Not running in Eclipse [duplicate]

I'm trying to install Java to use Eclipse (I followed all instructions to install Java and Eclipse) but my Eclipse is not starting due to some bad configuration I guess. I can't figure out why it's not working for me.
Eclipse Installation:
Extracted Eclipse at C:\eclipse
Created a shortcut to my desktop having target C:\eclipse\eclipse.exe
When I try to run Eclipse with this shortcut, I see following Eclipse splash screen for a second and it disappears. Eclipse does not start at all.
JAVA Installation:
Installed JDK at C:\Program Files\Java\jdk1.7.0_10
Installed JRE at C:\Program Files\Java\jre7
Environment Variables Configuration:
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_10
PATH = C:\Program Files\Java\jdk1.7.0_10\bin;
I tested my Java installation using the console and figured out this issue but I don't know how to fix it, and I guess this is causing Eclipse not to start.
Problem:
Go to Eclipse folder, locate eclipse.ini file, add following entry (before -vmargs if present):
-vm
C:\Program Files\Java\jdk1.7.0_10\bin\javaw.exe
Save file and execute eclipse.exe.
please try to execute java from
C:\Program Files\Java\jdk1.7.0_10\bin
i.e from the location where java is installed.
If it is successful, it means that the error lies somewhere in the classpath.
Also, this guy seems to have had the same problem as yours, check it out
Check that downloaded eclipse/JDK/JRE is compatible with your processor/OS architecture that is are they 32bit or 64bit?
Not able to run Appium {“message”:”A new session could not be created. (Original error: ‘java -version’ failed
I used Jdk 1.8 and JRE 1.8, Classpath is also set properly but I observed that Java command gives Error to initialization of VM (java/lang/NoClassDefFoundError: java/lang/Object)
Solution:
Uninstalled JRE and JDK completely
Installed JRE 1.8 then
Installed JDK 1.8
Set Classpath
check Java command works or not and its working
also able to execute the Appium program thru Eclipse Kepler Service Release 2 with JDK1.8 support
I had the same error in my case was when I needed to update jdk 7 to jdk 8, and my bad was just I installed jdk8 and I never installed jre8, only that, the error was solved immediately when I installed jre8.
Try placing the desired java directory in PATH before not needed java directories in your PATH.
I had the same issue on Windows 7 and I had to install both JDK and JRE and it's a success.
I faced the same problem,Eclipse splash screen for a second and it disappears.Then i noticed due to auto update of java there are two java version installed in my system. when i uninstalled one eclipse started working.
Thanks you..
I've observed this with STS and Eclipse and running java from CMD too on Windows 7/8/10 and following was my simple solution:
Actually, when I installed JDK 8 and STS/Eclipse it created one directory i.e. C:\ProgramData\Oracle\Java\javapath with the following files:
C:\ProgramData\Oracle\Java\javapath\java.exe
C:\ProgramData\Oracle\Java\javapath\javaw.exe
C:\ProgramData\Oracle\Java\javapath\javaws.exe
Along with that, it appended Path Environment variable of System with this location C:\ProgramData\Oracle\Java\javapath
I've just removed above entry from Path Environment variable of System and added the location of the actual JDK instead i.e. C:\Program Files\Java\jdk1.8.0_131\bin
Now that is not necessary to add that -vm option in eclipse.ini or
SpringToolSuite4.ini either.
I just spent about 1 hour to figure out possible solution for the same error.
So what I did under MS WIndows 7 is following
Uninstall all Java packages of all versions.
Download last packages Java SE or JRE for your 32 or 64 Windows and install it.
First install JRE and second is Java SE.
Open text editor and paste this code.
public class Hello {
public static void main(String[] args) {
System.out.println("test");
}
}
Save it like Hello.java
Go to Console and compile it like
javac Hello.java
Execute the code like
java Hello
Should be no error.
sometime you missed some file like I missed my one file rt.java
so better to check yours .........
C:\Program Files\Java\jdk1.8.0_112\jre\lib
0
I just spent about 1 hour to figure out possible solution for the
same error.
So what I did under MS WIndows 7 is following
Uninstall all Java packages of all versions.
Download last packages Java SE or JRE for your 32 or 64 Windows and
install it.
First install JRE and second is Java SE.
List item
Below error is thrown when there are multiple versions of jdk on your machine:
error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
so for this Just use below:
set PATH="JDK bin path" in cmd
I had a same issuse, my file location was in D-drive, and then i shifted to the c-Drive and it works.

Java Compilation error Not able to configure JAVA_HOME

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.

Categories

Resources