Error setting java home variable

I have recently downloaded Maven and followed the instructions given on this this page. I already have ant installed on my machine.
Now, if I want to verify that Maven is installed perfectly or not it is giving me error that JAVA_HOME is not set correctly, but same works perfectly fine for ANT.

For Maven I tried :
1. open cmd
2. type mvn -version
3. Error appeared :
C:UsersAdmin>mvn -version

ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:Program FilesJavajre7bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation

For ANT I tried and worked :
1. open cmd
2. type mvn -version
3. Apache Ant(TM) version 1.9.1 compiled on May 15 2013

I went to the directory to check that java.exe is actually there in that directory or not and it was there. I checked the environment variables they set fine. I restarted the system and checked again but same problem. Please let me know what am I missing.

asked Jun 26, 2013 at 8:44

paul's user avatar

4

JAVA_HOME should point to jdk directory and not to jre directory. Also JAVA_HOME should point to the home jdk directory and not to jdk/bin directory.

Assuming that you have JDK installed in your program files directory then you need to set the JAVA_HOME like this:

JAVA_HOME="C:Program FilesJavajdkxxx"

xxx is the jdk version

Follow this link to learn more about setting JAVA_HOME:

http://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/index.html

answered Jun 26, 2013 at 8:47

Juned Ahsan's user avatar

Juned AhsanJuned Ahsan

67.4k12 gold badges97 silver badges136 bronze badges

3

Do not include bin in your JAVA_HOME env variable

answered Jun 26, 2013 at 8:47

sadhu's user avatar

sadhusadhu

1,4198 silver badges14 bronze badges

Follow the instruction in here.

JAVA_HOMEshould be like this

JAVA_HOME=C:Program FilesJavajdk1.7.0_07

answered Jun 26, 2013 at 8:50

Ruchira Gayan Ranaweera's user avatar

1

JAVA_HOME = C:Program FilesJavajdk(JDK version number)

Example: C:Program FilesJavajdk-10

And then restart you command prompt it works.

answered Mar 31, 2018 at 19:19

karthik padav's user avatar

2

JAVA_HOME should point to jdk directory like in the image with new variable, like below

JAVA_HOME

PATH should point to jdk bin like below

PATH

answered Jun 28, 2022 at 13:26

Loki's user avatar

LokiLoki

1,1309 silver badges13 bronze badges

1

Just remember to add quotes into the path if you have a space in your path to java home.
C:Program Filesjavajavaxxx doesn’t work
but
«C:Program Filesjavajavaxxx» does.

answered Jun 4, 2014 at 22:27

jonorri's user avatar

2

Run the below command in your terminal and restart it.

> set JAVA_HOME="C:Program FilesJavajdk-xx.xx"

xx.xx is the java version

answered Nov 17, 2022 at 23:52

codeX's user avatar

codeXcodeX

4,5322 gold badges29 silver badges34 bronze badges

The JAVA_HOME should point to the JDK home rather than the JRE home if you are going to be compiling stuff, likewise — I would try and install the JDK in a directory that doesn’t include a space. Even if this is not your problem now, it can cause problems in the future!

answered Jun 26, 2013 at 8:46

nwaltham's user avatar

nwalthamnwaltham

2,0471 gold badge22 silver badges39 bronze badges

You are pointing your JAVA_HOME to the JRE which is the Java Runtime Environment. The runtime environment doesn’t have a java compiler in its bin folder.
You should download the JDK which is the Java Development Kit. Once you’ve installed that, you can see in your bin folder that there’s a file called javac.exe. That’s your compiler.

answered Jun 26, 2013 at 8:51

JREN's user avatar

JRENJREN

3,5723 gold badges26 silver badges44 bronze badges

JAVA_HOME should point to the home jdk directory and not to jdk/bin directory.

Make sure you have JDK installed in your computer and then you need to set the JAVA_HOME like this:

JAVA_HOME="C:Program FilesJavajdk" + "Your current installed version of jdk in your system"

answered Mar 15 at 17:07

Rohitash Singh's user avatar

Во многих статьях в интернете, документации к инструментам для разработки на Java и в книгах зачастую упоминается 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:Javajdk-11.0.6

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

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

echo %JAVA_HOME%
java --version

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

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

Резюме

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

How to fix JAVA_HOME errors

There’s nothing worse than installing your favorite Java-based application — such as Minecraft, Maven, Jenkins or Apache Pig — only to run into a JAVA_HOME is set to an invalid directory or a JAVA_HOME is not defined correctly error as soon as you boot up the program.

Well, there’s no need to fret. Here’s how to fix the most common JAVA_HOME errors.

How to fix JAVA_HOME not found errors

It’s worth noting that there aren’t standardized JAVA_HOME error messages that people will encounter. There are many different ways that a given JAVA_HOME error might be logged.

For example, one of the most common JAVA_HOME configuration problems arises from the fact that the environment variable has never actually been set up. Such a scenario tends to trigger the following error messages:

  • Error: JAVA_HOME not found in your environment
  • Error: JAVA_HOME not set
  • Error: JAVA_HOME is not set currently
  • Error: JAVA_HOME is not set
  • Error: Java installation exists but JAVA_HOME has not been set
  • Error: JAVA_HOME cannot be determined from the registry

How do you fix the JAVA_HOME not found problem?

Well, you fix this by in the Windows environment variable editor where you can actually add a new system variable. If you know your way around the Windows operating system, you should be able to add the JAVA_HOME environment variable to your configuration and have it point to the installation root of your JDK within minutes. The Windows 10 setting looks like this:

JAVA_HOME not found

Fix JAVA_HOME not found errors

As mentioned above, the JAVA_HOME variable must point to the installation root of a JDK, which means a JDK must actually be installed. If one isn’t, then you better hop to it and get that done.

The JAVA_HOME is set to an invalid directory fix

The next most common JAVA_HOME error message is JAVA_HOME is set to an invalid directory. The error message is delightfully helpful, because it tells you in no uncertain terms the environment variable does in fact exist. And, it also tells you it’s not pointing to the right place, which is helpful as well. All you need to do to fix this error is edit the JAVA_HOME variable and point it to the correct directory.

The JAVA_HOME environment variable must point to the root of the installation folder of a JDK. It cannot point to a sub-directory of the JDK, and it cannot point to a parent directory that contains the JDK. It must point directly at the JDK installation directory itself. If you encounter the JAVA_HOME invalid directory error, make sure the name of the installation folder and the value of the variable match.

An easy way to see the actual value associated with the JAVA_HOME variable is to simply echo its value on the command line. In Windows, write:

>/echo %JAVA_HOME%
C:/_JDK13.0

On an Ubuntu, Mac or Linux machine, the command uses a dollar sign instead of percentages:

:-$ echo $JAVA_HOME
/usr/lib/jvm/java-13-oracle

Find JAVA_HOME Ubuntu

How to find JAVA_HOME in Mac or Ubuntu Linux computers.

Steer clear of the JDK bin directory

One very common developer mistake that leads to the JAVA_HOME is set to an invalid directory error is pointing JAVA_HOME to the bin sub-directory of the JDK installation. That’s the directory you use to configure the Windows PATH, but it is wrong, wrong, wrong when you set JAVA_HOME. If you point JAVA_HOME at the bin directory, you’ll need to fix that.

This misconfiguration also manifests itself with the following error messages:

  • JAVA_HOME is set to an invalid directory
  • Java installation exists but JAVA_HOME has been set incorrectly
  • JAVA_HOME is not defined correctly
  • JAVA_HOME does not point to the JDK

Other things that might trigger this error include spelling mistakes or case sensitivity errors. If the JAVA_HOME variable is set as java_home, JAVAHOME or Java_Home, a Unix, Linux or Ubuntu script will have a hard time finding it. The same thing goes for the value attached to the JAVA_HOME variable.

The JAVA_HOME does not point to the JDK error

One of the most frustrating JAVA_HOME errors is JAVA_HOME does not point to the JDK.

Here’s a little bit of background on this one.

When you download a JDK distribution, some vendors include a Java Runtime Environment (JRE) as well. And when the JAVA_HOME environment variable gets set, some people point it at the JRE installation folder and not the JDK installation folder. When this happens, we see errors such as:

  • JAVA_HOME does not point to a JDK
  • JAVA_HOME points to a JRE not a JDK
  • JAVA_HOME must point to a JDK not a JRE
  • JAVA_HOME points to a JRE

To fix this issue,  see if you have both a JRE and JDK installed locally. If you do, ensure that the JAVA_HOME variable is not pointing at the JRE.

JAVA_HOME and PATH confusion

After you’ve downloaded and installed the JDK, sometimes another problem can plague developers. If you already have programs that installed their own version of the JDK, those programs could have added a reference to that specific JDK in the Linux or Windows PATH setting. Some programs will run Java using the program’s availability through the PATH first, and JAVA_HOME second. If another program has installed a JRE and put that JRE’s bin directory on the PATH, your JAVA_HOME efforts may all be for naught.

However, you can address this issue. First, check the Ubuntu or Windows PATH variable and look to see if any other JRE or JDK directory has been added to it. You might be surprised to find out that IBM or Oracle has at some prior time performed an install without your knowledge. If that’s the case, remove the reference to it from the PATH, add your own JDK’s bin directory in there, and restart any open command windows. Hopefully that will solve the issue.

Of course, there is never any end to the configurations or settings that can trigger JAVA_HOME errors. If you’ve found any creative solutions not mentioned here, please add your expert insights to the comments.

Hello fellow Ubuntu users,

I am trying to learn how to write modifications to Minecraft. In order to follow the tutorial I am using, I need to run a «gradlew». The command is as follows

./gradlew setupDecompWorkspace eclipse

This yields the following

ERROR: JAVA_HOME is set to an invalid directory: /usr/local/java/jdk1.8.0_20

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Obviously I don’t know what to do or even what this means. Any help is much appreciated.

asked Nov 27, 2014 at 20:05

Joseph_carp's user avatar

1

Before running the command try entering:

export JAVA_HOME="path_to_java_home"

Where path_to_java_home is the folder where your bin/java is.

If java is properly installed you can find it’s location, by using the command:

readlink -f $(which java)

Don’t forget to remove bin/java from the end of the path while putting it into JAVA_HOME

answered Nov 27, 2014 at 20:25

Andrew Onischuk's user avatar

Andrew OnischukAndrew Onischuk

5601 gold badge6 silver badges6 bronze badges

7

To make it automatic on Linux/Ubuntu, add these lines at the end of your .bashrc:

JAVA_HOME=$(dirname $( readlink -f $(which java) ))
JAVA_HOME=$(realpath "$JAVA_HOME"/../)
export JAVA_HOME

This gets java executable, then climbs up a directory level

To designate the default java version/executable on Debian/Ubuntu, run this once:

sudo update-alternatives --config java

This builds up on previous answer by Andrew Onischuk (thanks!)

answered Dec 7, 2016 at 20:05

Tudor Ilisoi's user avatar

0

Get your Java path using the command

whereis java

The following is a possible output depending on your default Java version

java: /usr/bin/java /usr/share/java /usr/lib/jvm/jdk1.8.0_241/jre/bin/java

Maven need to pick the Java location (home) so you can export the Java path using the following command

export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_241/jre

This will allow Maven to pick the java version and location in the /etc/environment file

Optionally you can add this in the /etc/environment manually using the following command

sudo nano /etc/environment

and edit the JAVA_HOME=/usr/lib/jvm/jdk1.8.0_241/jre/

answered Mar 11, 2020 at 8:01

Jose Mhlanga's user avatar

Try to edit /usr/bin/gradle

Comment the line «export JAVA_HOME=/usr/lib/jvm/default-java» with a #

this: #export JAVA_HOME=/usr/lib/jvm/default-java

answered Apr 15, 2018 at 20:49

starwatcher's user avatar

1

Run with sudo

sudo ./gradlew setupDecompWorkspace eclipse

You are not a sudo doer for running this command

So Add sudo to it.

answered Aug 21, 2020 at 13:08

Mayank Goyal's user avatar

Introduction

This is an article where the main focus is just to give an alternate solution about how to solve an error message. The error message appear when executing a certain command. That certain command is just a simple maven command. By typing ‘mvn’ command in the command prompt, it will execute the maven tool. It is a tool widely known for building application. For an example for building a Java application. The following is the command execution :

Microsoft Windows [Version 10.0.18363.628]
(c) 2019 Microsoft Corporation. All rights reserved.

C:UsersAdministrator>mvn

ERROR: JAVA_HOME not found in your environment.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation

C:UsersAdministrator>

Solution

So, the solution for the above error message is very simple. There is a hint in the output of the execution command. That hint is part of the error message. It is informing that the JAVA_HOME is not found in the environment. Moreover, there is an additional hint following after. It is that the JAVA_HOME is actually a variable. Additionally, that JAVA_HOME variable must be exist in the environment which in this case it is the machine as a PC or laptop running using Microsoft Windows. So, how can a JAVA_HOME variable available in it ?. The following are the steps for creating a JAVA_HOME variable to be exist in the environment. In this context, the environment of the PC or laptop running using Microsoft Windows. The steps are in the following order :

  1. Just type environment variable at the text field with the ‘Type here to search’ info. In other words, just execute the Windows environment variable settings. It appears as follows :

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven
  2. Next, click the Environment Variables button so the following one will appear :

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven

    See the JAVA_HOME environment variables in the system variable ?. That is actually the end goal alternative solution for solving the problem. When the error message appear, actually the JAVA_HOME environment variable does not exist in the first place. The image above just as an example showing the image of what the display is going to be. Just click the New… button. Fill the variable name as ‘JAVA_HOME’ and fill the value with the location of the Java installation folder location. In this context, it is ‘C:jdk-14’.

  3. Finally, in the system variables, just edit the Path variable. And the following display will appear :

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven

    See the %JAVA_HOME%bin entry as part of the path ?. The %JAVA_HOME% will refer to the variable as exist in the previous step. In this case, it is ‘C:jdk-14’. So, the value of ‘%JAVA_HOME%bin’ will refer to ‘C:jdk-14bin’.

  4. If it is not working, just place the original path as a new entry. Just add it as follows :

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven

    How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven

    In the above display, at the last empty line, just fill it with the full path of ‘C:jdk-14bin’.

  5. Last but not least, just run the command once more. If there is no other error message, the following output of the mvn command will exist as follows :

    Microsoft Windows [Version 10.0.18363.628]
    (c) 2019 Microsoft Corporation. All rights reserved.
    
    C:UsersPersonal>mvn -version
    Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 20:51:28+0700)
    Maven home: C:netbeans-8.2javamavenbin..
    Java version: 1.8.0_181, vendor: Oracle Corporation
    Java home: C:Program FilesJavajdk1.8.0_181jre
    Default locale: en_ID, platform encoding: Cp1252
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
    C:UsersPersonal>
    

    The above ‘mvn -version’ command is actually different with the JDK version above. Well, it is just only a purpose to show that after setting the JAVA_HOME environemnt variable, the maven command is actually working. The following is another example of maven command execution :

    C:UsersPersonal>mvn
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.115s
    [INFO] Finished at: Sat Feb 12 10:17:33 ICT 2022
    [INFO] Final Memory: 6M/123M
    [INFO] ------------------------------------------------------------------------
    [ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
    C:UsersPersonal>
    

JAVA_HOME is an environment variable used by various Java-based applications to locate JVM (JDK) on any system. Similarly, Maven also required the JAVA_HOME to be set correctly on your system.

The Problem:

When I tried to check the Maven version on our macOS PC, I got the following error in the output.

mvn --version 

The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

 JAVA_HOME environment variable is not defined correctly

Error: JAVA_HOME environment variable is not defined correctly

The Solution:

As the error message clearly shows that the JAVA_HOME environment variable is not set on my PC. So the simple solution is to set it correctly. Use the below steps to resolve this issue.

The macOS 10.5 (Catalina) and later version use the Zsh as the default shell. The older version uses the Bash shell. So first is to identify the shell that is running on your system. Open a terminal and type:

echo $SHELL 

For Zsh the output will be /bin/zsh and for the Bash shell the output will be /bin/bash.

Now, set the JAVA_HOME environment variable based on the active shell:

  • Zsh (/bin/zsh): Edit the ~/.zshenv file and append the below code.

    ~/.zshenv

    export JAVA_HOME=$(/usr/libexec/java_home)
  • Bash (/bin/bash): Edit the ~/.bash_profile file and append the below code.

    ~/.bash_profile

    export JAVA_HOME=$(/usr/libexec/java_home)

This should resolve the issue on your system. To confirm, open a new shell and print the JAVA_HOME environment variable value and also confirm with the command you were getting the error.

echo $JAVA_HOME 
mvn --version 

Error: JAVA_HOME is not defined correctly

Resolved: JAVA_HOME is not defined correctly

Note: If the issue is still not resolved after setting the environment variable correctly, make sure other scripts are not overriding it. You can find the script order of execution here.

android-studio-logo-long

I recently got back to Android programming and realized that Eclipse with ADT is no longer the default IDE. The good folks at Google have decided that Android Studio is now the official IDE for Android. Since I recently got a new laptop, I decided to install it and give it a try. (Be aware that the installer is pretty large. The file is around 850MB) After installing the application on my Windows 8 machine, I kept getting the following message:
No JVM installation found. Please install a 64-bit JDK. If you already have a JDK installed, define a JAVA_HOME variable
This error was occurring even though I had installed The latest version of the JDK. Here is a screenshot of the error I was getting

android_studio_java_home_error

How to fix the cissue

Below are the steps to take to fix the issue

1 – Install and Download the JAVA JDK

In order to fix the issue, you first have to make sure that you have a version of the JAVA JDK installed on your PC. You can download the latest version of the JDK from Oracle. If the JDK is istalled on your PC, you will be able to locate the path C:Program FilesJava. If this path does not exist, you probably do not have the JDK installed. If the path exists, you should find a folder called jdkX.X.X_X where X.X.X_X is the version of the JDK that you installed.

2 – Define the JAVA_HOME variable in your Environment Variables

Now all that is left is to setup the JAVA_HOME path in your environment variables. To do so, you need to right-click on “My Computer” and click “properties”. Once you do, you then have to find the Advanced System settings. Once you are in the advanced system settings, click on the Environment Variables button to setup the JAVA_HOME path.

android_studio_java_home_error_fix_part_1

When you click on the Environment Variables button, You will then see all the environment variables that currently exist on your PC. You can then click on the “New” button in “System Variables” to create a new environment variable called JAVA_HOME.

android_studio_java_home_fix_error_part_2

This environment variable should point to the base path of your JDK. In this tutorial, I am using version 1.8.0.25 of the JDK so my full path is “C:Program FilesJavajdk1.8.0_25”

android_studio_java_home_fix_error_part_3

Once you do this, the problem with JAVA_HOME should be resolved and you should now be able to use Android Studio without any problems. However, if you do not setup your JAVA_HOME path correctly, you will get the following error message

android_studio_java_home_invalid_path

One last piece of advice is that you should be aware that there is a 32-bit and 64-bit version of the JDK. Make sure that you download and install the version that matches your operating system. So, if you are running on a 64-bit version of WIndows, it is recommended to install the 64-bit version and vice-versa if you are running a 32-bit version of Windows. With that, you should be good to go. So far, I’ve been playing around with Android Studio for a few days and I have to say that I love it! I’ll miss Eclipse but Android Studio seems to be a winner.

Mifty Yusuf is a Montreal-based software developer who enjoys playing with new web technologies as well as comic books and illustrations. He beleives that, no matter what the question is, the answer is always Batman!

Latest from Android Arena

The good folks at Google release a sample app for Android that

The-Avengers-Movie-Poster-010

After releasing an initial version of my app on Google Play, I

After 4 months of development, I have completed and published my first

I’m having a problem running my flutter application in android studio.

It gives me the following message

Launching lib/main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Exception: Gradle task assembleDebug failed with exit code 1

Here is echo $JAVA_HOME and I have added the bin to my PATH

/usr/lib/jvm/openjdk-14.0.2_linux-x64_bin/jdk-14.0.2

I can run flutter from terminal via flutter run after upgrading gradle from gradle-5.6.2-all.zip to gradle-6.3-all.zip

I think the problem lies in android/gradlew in the following script

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

I tried copying it and running it and it runs with no problems with #!/usr/bin/env bash which is the shebang in gradlew

I tried reinstalling android studio, but it didn’t work. My flutter doctor --verbose is a mess. At first it couldn’t find android studio- said it is not installed. so I ran flutter config --android-studio-dir="/snap/bin" but now I get this output even though I have the plugins installed

:~$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.4, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
[!] Android Studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    ✗ android-studio-dir = /snap/bin
    ✗ Unable to find bundled Java version.
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.
:~$ flutter doctor --android-licenses
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
	at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
	at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
	at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
	at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
	at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 5 more

Thank you all hopefully I’m missing something simple!

Понравилась статья? Поделить с друзьями:
  • Error setting home directory
  • Error setting driver on unpooleddatasource
  • Error setting display mode lineage 2
  • Error setting display mode createdevice failed d3derr
  • Error setting certificate verify locations windows