Solution to mac Maven configuration error The JAVA_HOME environment variable is not defined correctly

Project scenario:

Ruoyi framework requires back-end deployment and packaging


Problem Description

For example: mac use command

mvn clean package -Dmaven.test.skip=true

The error is reported as follows

zsh: command not found: mvn

Cause Analysis:

The "zsh: command not found: mvn" error message indicates that the "mvn" command is not found on your system, which means that Maven is not installed correctly or is not in the system's PATH environment variable.


solution:

To resolve this issue, you can follow these steps:

1. Install Maven:

If you don't have Maven installed yet, you first need to install it. You can use a package manager such as Homebrew (on macOS), apt (on Ubuntu) or download and install Maven manually.

On macOS, you can use Homebrew to install Maven:

brew install maven

On Ubuntu, you can install Maven using apt:

sudo apt-get update
sudo apt-get install maven

Manually download and install Maven: You can download the Maven binary distribution package from the Maven official website (https://maven.apache.org/download.cgi), and then install it according to the instructions in the official documentation.

2. Confirm whether the installation is successful:

After the installation is complete, open a terminal and run the following command to confirm whether Maven was installed successfully:

mvn -version

If Maven is installed successfully, Maven version information will be displayed.

There is another bug

Matching Java Virtual Machines (5):
18.0.2.1 (x86_64) “Oracle Corporation” - “Java SE 18.0.2.1” /Library/Java/JavaVirtualMachines/jdk-18.0.2.1.jdk/Contents/Home
17.0.1 (x86_64) “Oracle Corporation” - “Java SE 17.0.1” /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home
1.8.321.07 (x86_64) “Oracle Corporation” - “Java” /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_321 (x86_64) “Oracle Corporation” - “Java SE 8” /Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
1.8.0_241 (x86_64) “Oracle Corporation” - “Java SE 8” /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-18.0.2.1.jdk/Contents/Home

There are multiple versions of Java Virtual Machines (JVMs) installed on your system. Maven may get confused because it doesn't know which Java version to use.

First, make sure that the environment variables in the terminal you are using are set to the version of Java you want to use. If you want to use Java 18.0.2.1, you can set the following environment variables:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-18.0.2.1.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

Make sure to add these commands to your shell configuration file (such as ~/.zshrc or ~/.bashrc) and make them effective by running the source command.

You can then run mvn -versionthe command again to ensure that Maven is using the Java version of your choice.

Finally return to the topic
and use it again

mvn clean package -Dmaven.test.skip=true

You can pack it out normally.

Guess you like

Origin blog.csdn.net/qzmlyshao/article/details/133345007