Score:0

How to set PATH, HOME, JAVA_HOME variables correctly for working with maven after Java-JDK installations?

US flag
P_Z

I visited the webpage at https://help.ubuntu.com/community/EnvironmentVariables and find out about setting environment variables and local user variables and have got a pretty clear picture. But I am still unable to understand how to set different system level and user level variables like PATH, JAVA_HOME, HOME for maven working with java. Also there are different newer versions of Java with JDK, JRE packages and the older seem to work though in many cases. So its get really puzzling when all sort of JAVA's JDK and JRE versions are installed. On my ubuntu machine (in a VM) I am unable to use maven with java as I got following warnings and errors when I run the bash script containing command #!/bin/bash mvn clean install:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< com.multichainjavaapi:MultiChainJavaAPI >---------------
[INFO] Building MultiChainJavaAPI 0.4.17-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MultiChainJavaAPI ---
[INFO] Deleting /home/kamran/Downloads/tmp/API Demo for Multichain/Multichain API Demo for Students/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MultiChainJavaAPI ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/kamran/Downloads/tmp/API Demo for Multichain/Multichain API Demo for Students/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MultiChainJavaAPI ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 89 source files to /home/kamran/Downloads/tmp/API Demo for Multichain/Multichain API Demo for Students/target/classes
[INFO] ---------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] ---------------------------------------------
[ERROR] /home/kamran/Downloads/tmp/API Demo for Multichain/Multichain API Demo for Students/src/main/java/multichain/MC/src/module-info.java:[8,1] modules are not supported in -source 8
  (use -source 9 or higher to enable modules)
[INFO] 1 error
[INFO] ---------------------------------------------
[INFO] ---------------------------------------------
[INFO] BUILD FAILURE
[INFO] ---------------------------------------------
[INFO] Total time:  6.925 s
[INFO] Finished at: 2023-01-27T21:11:15+05:00
[INFO] ---------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project MultiChainJavaAPI: Compilation failure
[ERROR] /home/kamran/Downloads/tmp/API Demo for Multichain/Multichain API Demo for Students/src/main/java/multichain/MC/src/module-info.java:[8,1] modules are not supported in -source 8
[ERROR]   (use -source 9 or higher to enable modules)
[ERROR] 
[ERROR] -> [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/MojoFailureException

I have eclipse and netbeans IDEs and the following on my ubuntu but I am unable to load the project Java API with above erros:

sudo which java
/usr/bin/java

sudo echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/>:/snap/bin

sudo mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.17, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-58-generic", arch: "amd64", family: "unix"

sudo echo $JAVA_HOME
/usr/lib/jvm/java-1.11.0-openjdk-amd64

sudo java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu220.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu220.04, mixed mode, sharing)

sudo javac -version
javac 11.0.17

sudo gedit /etc/profile.d/19.0.2.sh

export J2SDKDIR=/usr/lib/jvm/java-19.0.2

export J2REDIR=/usr/lib/jvm/java-19.0.2

export PATH=$PATH

export JAVA_HOME=/usr/lib/jvm/java-19.0.2

export DERBY_HOME=/usr/lib/jvm/java-19.0.2/db

Where I am doing wrong?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.