UIautomatorviewer Java Home issue - java

I am having a problem opening uiautomatorviewer on mac.
This is what I get on the terminal when I issue the command uiautomatorviewer:
???#???-MacBook-Pro-2 libexec % uiautomatorviewer
SWT folder '/usr/local/Caskroom/android-sdk/4333796/tools/lib/
ERROR: JAVA_HOME is set to an invalid directory: /usr/libexec/java_home
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.' does not exist.
Please export ANDROID_SWT to point to the folder containing swt.jar for your platform.
Any suggestion?

You have not defined JAVA_HOME in your system path. To do this:
Open Terminal
Confirm you have JDK by typing “which java”. It should show something like /usr/bin/java.
Check you have the needed version of Java, by typing “java -version”.
JAVA_HOME is essentially the full path of the directory that contains a sub-directory named bin which in turn contains the java.
For Mac OSX – it is: /Library/Java/Home
Set JAVA_HOME using this command in Terminal: export JAVA_HOME=/Library/Java/Home
echo $JAVA_HOME on Terminal to confirm the path
You should now be able to run your application
Note that this sets JAVA_HOME only for this session. If you want it to persist, you will have to add the command to your ~/.profile file. Below are instructions on how to accomplish this instead:
Open up Terminal.app (Applications >> Utilities >> Terminal)
Type: emacs .profile
add this to the end of the .profile file:
JAVA_HOME=/Library/Java/Home
export JAVA_HOME;
Save and exit emacs (ctrl-x, ctrl-s; ctrl-x, ctrl-c)
Open a new Terminal window (cmd-n) and type: $JAVA_HOME/bin/java -version
If you see something like:
java version “1.8.0_16″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.8.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.8.0_16-133, mixed mode, sharing)
Then you’ve successfully set your JAVA_HOME environment variable to the binary stored in /Library/Java/Home/bin/java
Source: SajeConsultants

Related

Javac -vresion is empty and how to set that?

I am working on Amazon ec2 for the first time and verified java version by using the command java -version and got the below results:
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)
And also run the command javac -version, but no results. From this, I have understood the javac is not set and none of the java related applications are running. Can anyone please tell me how to resolve this problem?
javac should be in the bin directory of the java installation dir and java in the jre/bin directory. You could run dirname $(readlink -e $(which java)) to find out the absolute path to the jre/bin dir and then modify it to the bin dir. The result is added to your PATH variable in your ~/.profile.
Add this line to your ~/.profile (or ~/.bash_profile or ~/.bashrc, whichever is read on startup)
export PATH=$PATH:$(readlink -e $(dirname $(readlink -e $(which java)))/../../bin)
Then logout and login again and test if javac -version works as expected.
AFTER SETTING YOUR SYSTEM VARIABLE TO JAVA_HOME YOU NEED TO DO THIS FOR IT WORK ON YOUR COMMAND PROMPT:
After setting the JAVA_HOME system variable you need to also set the path so you can use javac from the command prompt:
After setting the JAVA_HOME system variable:
Inside System Variables find "Path" and click "Edit"
At the end of the Path add this line: ";%JAVA_HOME%\bin" (without the double quotes)
Now click "Ok" and exit out of your command prompt window (If it's still open)
now try "javac -version" and it should work
You can also check your java version, JRE build version, and Java Server VM build by typing "java -version"

java command works but javac command doesn't?

I have downloaded the jdk 1.8.0_131
when I open the command prompt and write the following command - java -version it gives me the output
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
but when I write the following command: javac -version it gives me the output
'javac' is not recognized as an internal or external command,
operable program or batch file.
I have edit the system variables path to - C:\Progra~1\Java\jdk1.8.0_131\bin;
and when I do the following command : "C:\Program Files\Java\jdk1.8.0_131\bin\javac" -version
it gives me the output:
javac 1.8.0_131
So i know I have installed the correct java version
I also checked the above folder and did find a javac.exe there. Please help.
Edit:
I finally solved the problem. What I was doing is editing the "Path" variable when what I had to do was make a new variable called "PATH" and the the following details :
Variable name : PATH
Variable value : c:\Program Files\Java\jdk1.8.0_xx\bin;[Existing Entries...
Have you tried restarting "cmd.exe" since adding the bin directory to your PATH?
If you confirm that your PATH includes the java bin directory and you can see the "javac.exe" binary in that location, then all should be set up correctly.
In Windows you need to add path to the jdk_your_version/bin to the PATH variable. Add this line to the PATH:
C:\Progra~1\Java\jdk1.8.0_131\bin;
Save it. Then restart CMD since it does not update the path automatically for the open cmd. Then you should be able to see that javac is working:
javac -version

JAVA_HOME isn't being set/ saved to the path variable after the terminal instance is being closed

I have been using Java 1.7 until recently for my code base, and recently we have upgraded to java 8.
When am trying to set the JAVA_HOME variable in the .bash_profile / .bashrc file as :
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
and save it and use the source .bash_profile, the java -version points to :
Nitin-Vegis-MacBook-Pro:/ nitinsuryavegi$ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
but when i quit the terminal/ close the session and recheck the java - version it points back to the old version as this :
Nitin-Vegis-MacBook-Pro:/ nitinsuryavegi$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
Could you help me set the JAVA_HOME path permanently so i need not run the source .bash_profile every time i log into my terminal to keep changing the java -version from 1.7 to 1.8.
Also could someone help me understand :
The difference between .bash_profile and .bashrc file.
When i check the Java Runtime Version in my System Preferences it's been pointed to 1.8
Click here for reference, but when i check the java -version in the terminal it shown as :
java version "1.7.0_79"
What is difference between $JAVA_HOME and whereis java command ?
JAVA_HOME isn't being set/ saved to the path variable after the terminal instance is being closed
That is correct. In a normal shell, the changes that you make to environment variables in the shell are lost when the shell exit. (That applies for Linux, UNIX, Mac OS and even Windows "cmd.exe".)
The normal way to deal with this on Linux, UNIX and (I guess) Mac OS is to put shell commands to set the required variables either into one of the "rc" files for the shell, or into a wrapper script that you use to run your Java app (or whatever).
Could you help me set the JAVA_HOME path permanently so i need not run the source .bash_profile every time i log into my terminal to keep changing the java -version from 1.7 to 1.8.
On UNIX / Linux, one possibility would be to put global settings into /etc/profile. However, I don't know if that is right for MacOS. In your case, it could be that you are putting the settings into the wrong file, or that you are putting the wrong settings into the right file.
But this is what "man bash" says about shell initialization (on my Linux system):
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. ...
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
Also could someone help me understand: 1) The difference between .bash_profile and .bashrc file.
See above.
2) When i check the Java Runtime Version in my System Preferences it's been pointed to 1.8, but when I run
$ java -version
I get this output:
java version "1.7.0_79"
My guess would be that what is your shell initialization file(s) is overriding what you have set in the System Preferences. Also, I suspect that you may have misunderstood how the shell finds commands. As "man bash" explains, the shell will actually search for commands using the $PATH variable. That is the variable you should check to figure out why java -version and whereis java are not behaving as you expect.
You can check what the actual environment variable settings are in a shell by typing
$ export
3) What is difference between $JAVA_HOME and whereis java command ?
The first is an environment variable ... which isn't the command search path. It is conventionally used by third party tools to locate the JDK / JRE. But the JDK / JRE tools themselves ignore it!
The second is a builtin command that attempts to find a command on the shell's real command search path.
JAVA_HOME isn't being set/ saved to the path variable after the terminal instance is being closed
That is not correct. It is saved to the PATH variable as soon as you save it. However it doesn't affect currently open terminal windows, only new ones. Closing the terminal window has nothing to do with it.

Ionic Build can't find JDK set in JAVA_HOME even though it is the only Java install

When I installed Java JDK 1.8.x it initially was working, when I rebooted the next day after shutting down over night I get this when I build:
$ ionic build android
Updated the hooks directory to have execute permissions
Running command: d:\installs\nodejs\node.exe d:\htdocs\publicworks\mobile\hooks\after_prepare\010_add_platform_class.js d:/htdocs/publicworks/mobile
add to body class: platform-android
Running command: d:\htdocs\publicworks\mobile\platforms\android\cordova\build.bat
ANDROID_HOME=c:\Users\mtpultz\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45\bin
Running: d:\htdocs\publicworks\mobile\platforms\android\gradlew cdvBuildDebug -b d:\htdocs\publicworks\mobile\platforms\android\build.gradle -Dorg.gradle.daemon=true
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_45\bin
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
d:\htdocs\publicworks\mobile\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "d:\htdocs\publicworks\mobile\platforms\android\gradlew cdvBuildDebug -b d:\htdocs\publicworks\mobile\platforms\android\build.gradle -Dorg.gradle.daemon=true"
But Java is most definitely installed in this directory and nowhere else??? In my terminal:
java -version
Produces the proper output for my JDK:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
The environment variables are set to:
JAVA_HOME =
C:\Program Files\Java\jdk1.8.0_45\bin
and the path contains:
D:\installs\nodejs;
C:\Users\mtpultz\AppData\Roaming\npm;
D:\installs\apache-ant\bin;
C:\Users\mtpultz\AppData\Local\Android\android-sdk\tools;
C:\Users\mtpultz\AppData\Local\Android\android-sdk\platform-tools;
Any suggestions?
JAVA_HOME should be set to the home directory of java and not to bin. So replace this:
C:\Program Files\Java\jdk1.8.0_45\bin
with
C:\Program Files\Java\jdk1.8.0_45
java/bin dir is added to PATH system variable to run java from anywhere.
Do one thing. This will Help You
Remove "\bin" from your JAVA_HOME path. Mean give path only till.
C:\Program Files\Java\jdk1.8.0_45
It will work with you.
For Linux user:
$sudo gedit $HOME/.bashrc
write at end
#Android Path
export ANDROID_HOME=${HOME}/Android/Sdk
export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools
export PATH
#JAVA
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/
export JAVA_HOME
$source ~/.bashrc
after that open
$sudo gedit /etc/environment
and add at end
JAVA_HOME="/usr/lib/jvm/java-8-oracle/"
$source /etc/environment
after wasting 3 days finally i got some solutions. these are definitely works when you found these errors.
1.Error: JAVA_HOME is set to an invalid directory
JAVA_HOME should be set to the home directory of java and not to bin. So replace this:
C:\Program Files\Java\jdk1.8.0_45\bin
with
C:\Program Files\Java\jdk1.8.0_45
java/bin dir is added to PATH system variable to run java from anywhere
Failed to install 'cordova-plugin-whitelist': Error using forcedroid command line
check your environments variables
1. android platforms tools
2. android tools
3. sdk location
4. git location
cordova - Error: Failed to fetch platform android
the only solution is
cordova platform add android --nofetch
Make sure you use the Java SE SDK and not the Java EE SDK, that solved the problem for me.
Make sure that your JAVA_HOME is having the following path and install JDK SE.
C:\Program Files\Java\jdk1.8.0_131

Java runtime not found in OSX 10.9.1 while running solR

I want to run solR in mac OSX 10.9.1. So I installed JRE latest version. Then, I downloaded solR and expanded the folder. But when I try to run this jar file in example folder, I get this msg "no java runtime present", mentioned below.
Do I need to add JAVA_HOME env variable like we do in windows? If so, please tell me how.
Ananyas-MacBook-Pro:~ ananya$ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build
1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
Ananyas-MacBook-Pro:~ ananya$ cd /Users/ananya/Desktop/VT\ study/solr-4.6.1/example
Ananyas-MacBook-Pro:example ananya$ java -jar start.jar
No Java runtime present, requesting install.
Ananyas-MacBook-Pro:example ananya$
Thanks.
"Do I need to add JAVA_HOME env variable like we do in windows?"
Test to see if/where Java is on your path in a terminal:
echo $JAVA_HOME
If the path to Java is wrong or missing you can add and Environmental Variable to ~/.bash_profile like so
JAVA_HOME=/usr/bin/java #or whatever your path is
export PATH=$PATH:$JAVA_HOME/bin/
You can open ~/.bash_profile in a terminal with nano
nano ~/.bash_profile.
Nano hint: writeout means save.
You'll need to reopen your terminal to load the new path. Or, reload it with the source command.
source ~/.bash_profile
Alternatively, if you like saving keystrokes you can type
. ~/.bash_profile

Categories

Resources