WSL: why does Maven fail? - java

I'm using WSL (Ubuntu shell) in Windows. I installed Java and Maven and once I run Maven from Ubuntu shell I get:
$ mvn
[ERROR] Error executing Maven.
[ERROR] java.lang.IllegalStateException: Unable to load cache item
[ERROR] Caused by: Unable to load cache item
[ERROR] Caused by: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper
Of course it doesn't happen once I run Maven from the "regular" Windows shell.
Do you know what I can do to resolve it?
Edit:
$ echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
$ java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.2+8-Ubuntu-120.04, mixed mode, sharing)
$ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.2, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.10.16.3-microsoft-standard-wsl2", arch: "amd64", family: "unix"

Thanks to #Turing85 for referring me to the bug.
I stayed with Java 17, but I downloaded Maven version 3.8.5.
You can see an explanation here how to do it:
https://websiteforstudents.com/how-to-install-apache-maven-on-ubuntu-linux/

Related

Intellij 'mvn' is not recognized as an internal or external command

I have installed maven on my pc and if I type "mvn --version" in the cmd, I get:
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T14:57:37+03:00)
Maven home: C:\Users\mmmm\Downloads\apache-maven-3.3.3-bin\apache-maven-3.3.3
Java version: 1.8.0_251, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_251\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
The problem is that from Intellij, if I try to do a mvn clean install from the terminal, I get "'mvn' is not recognized as an internal or external command,
operable program or batch file."
My system variables contain these:
M2_HOME = C:\Users\mmmm\Downloads\apache-maven-3.3.3-bin\apache-maven-3.3.3
M2 = %M2_HOME%\bin
Path = %M2_HOME%\bin
How can I fix this?
I have also installed JDK 1.8 and Maven3 as below:
>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
>javac -version
javac 1.8.0_121
>mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\SDK\maven\apache-maven-3.6.3\bin\..
Java version: 1.8.0_121, vendor: Oracle Corporation, runtime: C:\java\jdk1.8\jre
Default locale: en_US, platform encoding: MS932
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
I found the problem is the environment variables of terminal:
Copy your bin path of JDK and Maven into it!! And then restart your Terminal.
I had a similar issue that was fixed after I pointed M2_HOME to Intellij's maven plugin path instead of pointing to a path associated with a separate maven installation.
"C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\plugins\maven\lib\maven3"
I also added %M2_HOME%\bin to PATH.

Maven: No build successful or [scanning for projects] message after mvn install

I am not getting any scanning for projects or build successful or build failure message after running typing mvn install or mvn clean install.
LM-SFA-11002477:com.stubhub.mapreduce.hbasehexatodecimal navparmar$ mvn clean install
log4j:WARN No appenders could be found for logger (org.apache.maven.cli.logging.impl.UnsupportedSlf4jBindingConfiguration).
log4j:WARN Please initialize the log4j system properly.
Downloading: https://mvnrepository.stubcorp.dev/nexus/content/groups/stubhub-public/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
LM-SFA-11002477:target navparmar$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
mvn -version
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T12:39:06-07:00)
Maven home: /usr/local/Cellar/maven/3.5.0/libexec
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"
You may have included multiple slf4j jars versions in your project. Please find the dependency hierarchy tab in your pom.xml and exclude the unecessary jar version from your pom.xml.
If you still getting issue then try to build the project in debug mode.So that you will get detailed error description.
mvn clean compile install -X

Cannot use string in case even though I am using Java 8?

Sorry that I have to ask this quite easy question. I am using OSX with Java 8 installed and maven. But I can't mvn install a code using string in case. Can you point out what's wrong?
mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /usr/local/apache-maven-3.3.9
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Default locale: zh_TW, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.2", arch: "x86_64", family: "mac"
Code error msg
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/Briancheung/Documents/projects/webcompiler/dev/parser/src/main/java/project/Preference.java:[40,23]
strings in switch are not supported in -source 1.5
(use -source 7 or higher to enable strings in switch)
[INFO] 1 error
It seems that maven is not using Java 8 JDK I have installed. Thank you for any response.
java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
javac -version
javac 1.8.0_45

Build Jenkins and deploy on Heroku

Uninstalled all version of java from my machine and reinstalled the version 7 of Oracle:
$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
$ mvn -v
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: pt_BR, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-61-generic", arch: "amd64", family: "unix"
why when using the foreman start the application works locally and when I do the build by Jenkins and implant in heroku the application launches java.lang.UnsupportedClassVersionError exception and Unsupported major.minor version 51.0? I'm using the wrong dependence? Where am I wrong?
I'm not getting solve this problem.
Any help will be very welcome!

Failure executing javac, but could not parse the error:

Given the following:
> mvn clean compile
...
[ERROR] Failure executing javac, but could not parse the error:
/bin/sh: c:/progra~1/java/jdk1.6.0_24/bin/javac: No such file or directory
checked that my mvn and java versions were correct:
$mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T07:57:37-04:00)
Maven home: /Users/kevin/Downloads/apache-maven-3.3.3
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.4", arch: "x86_64", family: "mac"
$java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Unsure of a problem with my brew-installed mvn, I removed it and downloaded mvn-...bin.zip from Apache. Then I set my PATH, verified that mvn -version and java -version spit out the same versions. But, I'm still having the same problem.
I looked at the top 3 (from search) StackOverflow results, but have not gotten any further:
Maven compilation error. Failure executing javac, but could not parse the error:javac: invalid flag: -s
Maven, Failure executing javac: Compilation failure
Compilation error: Failure executing javac, but could not parse the error
You should check your JAVA_HOME variable or pom.xml for this Windows-specific path: c:/progra~1/java/jdk1.6.0_24/bin/javac and change it to your real JDK installation path (/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre?).
I ran into similar issue when i started using a newer version of java.
In your case Maven is using java 6. Try setting JAVA_HOME environment variable to correct JDK version. I guess JAVA_HOME is pointing to jdk 1.6.

Categories