1

I'am trying to get Maven running. I have installed JDK and Maven. Thus I have been trying to set the Java_home variable for three days now, I cannot get it working.

I have followed the instructions of another askUbuntu Topic:

This doesn't work. Not any explanation explains how to set the path, they rather give examples how to set their path.. So I have no idea whats wrong with mine, it is the location to the file in the etc/environment.

I installed maven by downloading the correct latest version on the site. Extracted and installed it in opt directory using known sudo-commands.

I created the maven.sh file myself, since there wasn't a file like this in the profile.d directory. You can see how I set that in the cat output and the picture below.

The Java_Home set in my etc/environement though is: JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64";This used to be /usr/opt/jdk-13.0.1 (which you will see the terminal give back the first time), because thats how I thought It needed to work according to explanation how to install Maven.

When I source my maven.sh, I get the right mvn -version in the terminal. When I close terminal, I have to source it again.

Here my terminal feedback on the versions, rember that after the first 3 commands (version -java, -mvn and echo) I source my maven.sh file manually:

mussche@MuskiProBook:~$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

mussche@MuskiProBook:~$ mvn -version The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program.

mussche@MuskiProBook:~$ echo $JAVA_HOME /usr/opt/jdk-13.0.1

mussche@MuskiProBook:~$ java -version openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

mussche@MuskiProBook:~$ mvn -version Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f) Maven home: /opt/maven Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: nl_NL, platform encoding: UTF-8 OS name: "linux", version: "5.11.0-27-generic", arch: "amd64", family: "unix"

mussche@MuskiProBook:~$ echo $JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64

mussche@MuskiProBook:~$ cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

mussche@MuskiProBook:~$ cat /etc/profile.d/maven.sh export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 export M2_HOME=/opt/maven export MAVEN_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}

/etc/profile.d/maven.sh content:

/etc/profile.d/maven.sh

How to install maven correct? How to set the variables, where to find the files that need to be changed, and exactly how to change them?

2 Answers2

0

I solved the issue. I don't exactly why, but after several restarts (not after just one) the path got set instantly instead of me having to manually source it.

Kr,

Yannick

0

For ubuntu - to add Java-openJdk and Maven

  1. Install OpenJDK through CLI
  2. Move Maven and Gradle to /opt/

Working config for openjdk-17

sudo vim /etc/profile


export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar

export GRADLE_HOME=/opt/gradle-8.1 PATH=$PATH:$GRADLE_HOME/bin

export MAVEN_HOME=/opt/apache-maven-3.9.1 PATH=$PATH:$MAVEN_HOME/bin

I saw one restart required, then check mvn --version