Java can find java home

JAVA_HOME : where is java installed

I’m trying to set the JAVA_HOME to get tomcat 7 to work with no success. I’m using CentOS 6.3. Here is what I did so far: which java /usr/bin/java so I edited the .bash_profile, I added export JAVA_HOME=/usr/bin/java didn’t work. I searched online and found another user on stackoverflow who found it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java I searched on my computer and found that java is located in /usr/lib/jvm/jre-1.6.0-openjdk/bin I then changed the JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/bin , tried to start tomcat but server can’t be found. How do I find where java was installed? I didn’t install it myself; it was installed during linux installation. Thanks in advance, Mike

JAVA_HOME is the directory that contains the bin directory, in this case /usr/lib/jvm/jre-1.6.0-openjdk .

I cd into the directory that tomcat was extracted to, then I type bin/startup.sh I was told to start 2 terminals. Type tail -f /server/apache-tomcat-7.0.33/logs/catalina.out in the first one then move the second terminal and type bin/startup.sh I got this /server/apache-tomcat-7.0.33/logs/catalina.sh : line 389 : /usr/bin/java/bin/java : Not a directory I changed JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk, it didn’t work

3 Answers 3

export JAVA_HOME=/usr should do it. The script runs $JAVA_HOME/bin/java

Thank you! It finally worked but now I have another problem if I type localhost.com:8080 , I get server not found. If I type 127.0.0.1:8080 , the Apache software foundation page displays. This computer isn’t connected to the internet.

that won’t work then. localhost.com is not your machine, it’s a real domain. You probably want to access localhost:8080

Читайте также:  Package java util date

Just out of curiosity, if i want it to work locally will all I need to do is set up a dns? I don’t care if it’s localhost.com or anything else. I’m just curious as to how the setup of .com domain will work.

The strictly correct answer is this:

export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk 

The issue is that on a typical Linux system you access the java command (etc) via symbolic links that are created / managed by the alternatives command. This allows you to make a system-wide choice over which of the java installations should be used by default; i.e. via commands in /usr/bin .

The second issue this that the JAVA_HOME environment variable should point at the Java installation directory. The «bin» directory is a subdirectory of the installation directory. (Look at the contents of «/usr/lib/jvm/jre-1.6.0-openjdk» !!)

While export JAVA_HOME=/usr/bin will work for locating the commands, it won’t work if the Java application needs to find other files in the installation; e.g. the «rt.jar» file.

This «fine distinction» possibly doesn’t matter for Tomcat, but it is likely to matter for other Java software that uses the JAVA_HOME convention.

Footnote: if you are using an Oracle Java for Linux installation, the default installation directory will be a subdirectory «/usr/java». Sadly, the Oracle installer doesn’t understand that Linux «alternatives» system. You either have to register the alternatives for each of the Java commands by hand (tedious!!) or add the installation’s «bin» directory to your PATH.

Источник

Переменная окружения JAVA_HOME

Во многих статьях в интернете, документации к инструментам для разработки на Java и в книгах зачастую упоминается JAVA_HOME. Что же такое JAVA_HOME?

Что такое JAVA_HOME

JAVA_HOME это переменная окружения, указывающая на директорию с установленным JDK (Java Development Kit, комплект разработчика Java). JAVA_HOME это соглашение, используемое во многих программах из экосистемы Java.

Какие программы используют JAVA_HOME

  • Intellij IDEA, Eclipse, NetBeans
  • Apache Maven, Apache Ant, Gradle
  • Apache Tomcat
  • Jenkins

Некоторые игры, написанные на Java (например, Minecraft), тоже могут требовать установленной переменной JAVA_HOME.

Ошибки, связанные с JAVA_HOME

Если переменная окружения JAVA_HOME не определена, некоторые программы могут выдавать следующие ошибки:

  • Переменная среды java_home не определена
  • Cannot determine a valid Java Home
  • JAVA_HOME is set to an invalid directory
  • JAVA_HOME is not defined correctly
  • JAVA_HOME environment variable is not set
  • JAVA_HOME command not found
  • JAVA_HOME not found in your environment
  • JAVA_HOME does not point to the JDK

При появлении таких ошибок просто установите переменную JAVA_HOME

Как установить переменную окружения JAVA_HOME в Windows

Сперва вам нужно установить JDK или JRE.

  • Установите JDK, если вы занимаетесь разработкой программ на Java
  • Установите JRE, если вам нужно только запустить прикладную программу на Java

После установки JDK либо JRE запишите путь установки, он понадобится.

Теперь щёлкните правой кнопкой на «Мой компьютер» → «Свойства» → «Дополнительные параметры системы» → «Переменные среды…». В разделе «Системные переменные» нажмите кнопку «Создать…» и укажите следующие данные:

Имя переменной JAVA_HOME
Значение переменной Путь к директории JDK / JRE, например:
C:\Java\jdk-11.0.6

Сохраните изменения, кликнув «OK». Теперь выберите в списке переменную окружения Path и нажмите «Изменить…». В конце списка добавьте строчку со значением «%JAVA_HOME%\bin«

Для проверки откройте консоль (Win+R, cmd) и укажите последовательно укажите две команды:

Если вы правильно установили JDK/JRE и правильно установили переменные окружения, вы увидите вывод наподобие этого:

Это будет служить результатом того, что переменная JAVA_HOME установлена правильно и Java работает из командной строки.

Резюме

В данной статье мы рассказали вам, что являет собой переменная окружения JAVA_HOME, где она используется и как её корректно указать.

Источник

Android Studio can’t find JAVA_HOME

]()![enter image description here

I can’t seem to get my Android applications to compile due to a really annoying exception from Android Studio:

Execution failed for task ':myapp-services:compileDebugJava'. Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory. 
export JAVA_HOME="/usr/lib/jvm/java-7-oracle/" 
export JAVA_HOME="/usr/lib/jvm/java-7-oracle/" 
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) 

I have also logged out and logged back in again to my session. I’m really not sure what I’m missing here. Why can’t Android Studio compile my application?

based on the output from which javac maybe you don’t really have the JDK installed at /usr/lib/jvm/java-7-oracle . Is /usr/bin/javac a symlink? (to where?)

My JAVA_HOME is set to JAVA_HOME = C:\Program Files\Java\jdk-13.0.1 but android studio produces an error on startup. That directory is valid on my system.

9 Answers 9

I solved it by updating build.gradle (Top-Level) with

classpath 'com.android.tools.build:gradle:2.1.2' 
rm ~/.AndroidStudioPreview/config/options/jdk.table.xml 

What seems to have happened is that something was configured for a previous version of Android Studio and this configuration lived too long 🙂

Brilliant! For me it was ~/.AndroidStudioBeta/config/options/jdk.table.xml but that’s the same principle. I switched from opensdk to oracle jdk and couldn’t compile anymore. Note that you need to restart studio in order to re-index and make it work.

On Windows, this is C:\Users\\.AndroidStudio\config\options\jdk.table.xml, but removing it still didn’t fix the error.

I guess because my error starts with «Error:Execution failed for task ‘:CordovaLib:compileDebugJavaWithJavac’.».

I was getting this error too. After many hours trying to solve it, I’ve managed to solve the problem.

In my case, executing the app from command line did the trick!

Here’s what I did (I’m using Windows 10). Please, run these commands on the root of the project (where we have the app directory):

1) gradlew assembleDebug

2) adb install -r app\build\outputs\apk\app-debug-unaligned.apk

  • After executing this line, you’ll see the message: [100%] /data/local/tmp/app-debug-unaligned.apk pkg: /data/local/tmp/app-debug-unaligned.apk Success

3) adb shell am start -n package_name/package_name.MainActivity, where «package_name» must be replaced by your package name (you can find it on AndroidManifest.xml). If «MainActivity» is not your launcher activity, replace it by your own activity.

  • You’ll see the message: Starting: Intent < cmp=package_name/.MainActivity >, where «package_name» is your app’ package name.

It will install the app on your device and after that, Android Studio seems to find the JAVA_HOME variable again. You should be able to run the app by hitting the «Run» button on Android Studio.

I have solved it by updating classpath of (build.gradle (Project:projectName))

classpath 'com.android.tools.build:gradle:2.2.3' 

Go To Settings->Project Structure->JDK path and change it to the system JDK instead of Studio JDK, you will be up and running.

update build.gradle module

 classpath 'com.android.tools.build:gradle:3.0.1' 

Just downloaded the latest version (android-studio-ide-1641136.dmg) and I just changed the Info.plist file content. It’s originally configured to use 1.6* as of Java version. I have 1.8 installed, so just changed to 1.8* and worked.

I have found a problem with the Android Studio studio.bat file and here it is

 ::------------------------------------------------------ :: Locate a JDK installation directory which will be used to run the IDE. :: Try (in order): ANDROID_STUDIO_JDK, ..\jre, JDK_HOME, JAVA_HOME. :: --------------------------------------------------------------------- IF EXIST "%ANDROID_STUDIO_JDK%" SET JDK=%ANDROID_STUDIO_JDK% IF NOT "%JDK%" == "" GOTO jdk IF EXIST "%~dp0\..\jre" SET JDK=%~dp0\..\jre IF NOT "%JDK%" == "" GOTO jdk IF EXIST "%JDK_HOME%" SET JDK=%JDK_HOME% IF NOT "%JDK%" == "" GOTO jdk IF EXIST "%JAVA_HOME%" SET JDK=%JAVA_HOME% IF "%JDK%" == "" GOTO error 

Do you get the problem in the last 2 lines of code?
It seems that if your environmental variable is %JAVA_HOME% the batch file will GOTO error and an error message will be displayed and that’s it NO ANDROID STUDIO FOR YOU, even though %JAVA_HOME% contains a valid path but if the environmental variable is something like %ANDROID_STUDIO_JDK% like mine is because I created it myself then it will work

Источник

Checking/getting JAVA_HOME Variable from Java

Inside a Java program, how can I read the JAVA_HOME variable (to be sure it is set the correct way)? Similarly, how can I get the path of the bin folder? That is, the path usually set in Windows via: path %path%;%JAVA_HOME%\bin Note: I am using the OpenJDK build by Alexkasko.

@AndrewThompson: I am using a portable R distribution and I need a portable Java as well (in order to use some R-Java Interfaces). I copy the OpenJDK files in the portabla R folder then I need to set the path to them.

5 Answers 5

String javaHome = System.getProperty("java.home"); 

I get: String javaHome = System.getProperties(«java.home»); ^ required: no arguments found: String reason: actual and formal argument lists differ in length 1 error

Thanks, System.getenv(«JAVA_HOME») didn’t work for me as the variable was not exported (non-environment variable)

Java properties and environment variables are two different things, and from the question it looks like he specifically asked for the latter.

Since both PATH and JAVA_HOME are environment variables, you should be able to read both of their values in a similar way:

String javaHome = System.getenv("JAVA_HOME"); String path = System.getenv("PATH"); 

You have to use System.getenv(«JAVA_HOME»);

On windows you could execute the set command from you application as you would do in your cmd and afterwards handle the output:

Process p; p = Runtime.getRuntime().exec("set JAVA_HOME"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); 

But as answered by the others

However if anyone needs an alternative, see above. 😀

Источник

Оцените статью