maven ignores maven.compiler.source - maven

I have
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
in my pom.xml.
If I run mvn clean install then I can't run the compiled classes with Java 1.8 (I get crashes with errors like java.lang.NoClassDefFoundError: Could not initialize class when I try to).
I am forced to run
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home mvn clean install
if I want it to be able to run the built jar with java 8 without crashes.
How can I make it actually use the correct JDK that I want?
Here is how my machine seems to be set up by default
$ mvn -version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T19:41:47+01:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.2", arch: "x86_64", family: "mac"
$ java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
$ echo $JAVA_HOME
$

Related

How to change JVM Gradle version via SDK

I''ve installed gradle via SDK, and my java version is 11.0.14. But whe I run gradle -v it returns:
Gradle 6.5
------------------------------------------------------------
Build time: 2020-06-02 20:46:21 UTC
Revision: a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4
Kotlin: 1.3.72
Groovy: 2.5.11
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 1.8.0_321 (Oracle Corporation 25.321-b07)
OS: Linux 5.4.0-109-generic amd64
Java --version:
java 11.0.14 2022-01-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.14+8-LTS-263)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.14+8-LTS-263, mixed mode)
But I want this gradle JVM to be 11.0.14, how can I change this?

Centos 7: Java version for Maven

I have a open jdk installed on my centos 7. I would like maven to use java 1.8. I wouldn't want to break the machine's java. What would be the best way to achieve this?
Running: mvn -v
`Maven home: /usr/share/maven
Java version: 1.7.0_131, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el7_3.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-514.10.2.el7.x86_64", arch:
"amd64", family: "unix"`
running: java -version
`openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)`
Here is my mvn config
running : cat /usr/bin/mvn
`#!/bin/sh
if [ -f /usr/share/java-utils/java-functions ] ; then
. /usr/share/java-utils/java-functions
set_jvm
set_javacmd
fi
export M2_HOME="${M2_HOME:-/usr/share/maven}"
export JAVA_HOME; $M2_HOME/bin/mvn "$#"`
Running $yum search java | grep openjdk
`java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on
java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment with full debug on
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos with full debug on
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full
java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with
java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full
java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in
java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle for packages with`
I doubt you'll "break anything" by changing Maven's JRE to Java 1.8.
Run alternatives --config java to see what JVMs are currently installed. Ideally, if you have both JRE7 and JRE8, you should see both listed.
Simply modify your /usr/bin/mvn to point to the desired path.
Run mvn -version again. You should see the updated configuration.
ran:
yum install java-1.8.0-openjdk-devel
then:
alternatives --config javac
Selected the version required for my project.
Thanks for all the replies!

Atlassian SDK + Win10 => -Dmaven.multiModuleProjectDirectory system property is not set

I am trying to use Atlassian SDK 6.2.9. on my laptop with Win10, but there is a maven problem.
Java:1.8.0_101
Mvn: 3.3.9 (M2_HOME)
CMD full stack says more:
c:\>atlas-version
ATLAS Version: 6.2.9
ATLAS Home: C:\ProgramData\Atlassian\atlassian-plugin-sdk-6.2.9
ATLAS Scripts: C:\ProgramData\Atlassian\atlassian-plugin-sdk-6.2.9\bin
ATLAS Maven Home: C:\ProgramData\Atlassian\atlassian-plugin-sdk-6.2.9\apache-maven-3.2.1
AMPS Version: 6.2.6
--------
Executing: "C:\ProgramData\Atlassian\atlassian-plugin-sdk-6.2.9\apache-maven-3.2.1\bin\mvn.bat" --version -gs C:\ProgramData\Atlassian\atlassian-plugin-sdk-6.2.9\apache-maven-3.2.1/conf/settings.xml
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.c:\>
My question is how can I figure this mvn problem out?
Thanks a lot

Error: JAVA_HOME is not defined correctly, when installing Maven on Mac

It is suppose to be easy, but I'm having great difficulty installing Maven on to my mac 10.11.4.
I have created M2_HOME and PATH for Maven, but when I type in mvn --version, the terminal tell me
/Users/justin/apache-maven-3.3.9/bin/mvn: line 53: uname: command not found
/Users/justin/apache-maven-3.3.9/bin/mvn: line 143: which: command not found
/Users/justin/apache-maven-3.3.9/bin/mvn: line 171: which: command not found
Error: JAVA_HOME is not defined correctly.
We cannot execute
Why is this happening?
You need JAVA_HOME to be defined, as covered in installation guide.
Check out this answer for additional details for MacOS.
For macOs Ventura 13.1
If you installed java openJdk version 11 using Homebrew:
brew install java11
Then, your java is installed on:
/opt/homebrew/Cellar/openjdk#11/11.0.17/libexec/openjdk.jdk/Contents/Home
So, you must understand that this is you JAVA_HOME environment variable.
You need to add the java '/bin' folder to your PATH environment variable in order to have it working on your terminal. Also, you need to create the JAVA_HOME environment variable in order to maven to know about your java.
Therefore, you must open:
/Users/<yourUser>/.zshrc
Add
export JAVA_HOME="/opt/homebrew/Cellar/openjdk#11/11.0.17/libexec/openjdk.jdk/Contents/Home"
export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"
Save your changes, close the file. Now you can open your terminal and type:
java -version
and then,
mvn -version
and this is what you should get:
example#example441 ~ % java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment Homebrew (build 11.0.17+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.17+0, mixed mode)
example#example441 ~ % mvn -version
Apache Maven 3.8.7 (xxxxxxxxxxxxxxxxxxxxxxxxxxx)
Maven home: /opt/homebrew/Cellar/maven/3.8.7/libexec
Java version: 11.0.17, vendor: Homebrew, runtime:
opt/homebrew/Cellar/openjdk#11/11.0.17/libexec/openjdk.jdk/Contents/Home
Default locale: pt_BR, platform encoding: UTF-8
OS name: "mac os x", version: "13.1", arch: "aarch64", family: "mac"

Maven & architecture - how to build all available architectures?

I'm actually trying to compile some native code, but that I think that has to wait for a moment. Please consider the following as building up to resolving Native builds with Maven-NAR-pluggin.
We have 64 bit windows machines currently which are quite capable of also compiling 32 bit software. (yes I know, still waiting for the 128 bit)
How do we configure Maven pluggins / POM to compile both?
aka override the architecture as provided from the JRE that was found in JAVA_HOME
C:\Data\dev\zlib\minizip>mvn -X compile
+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.6.0_31
Java home: C:\Program Files\Java\jdk1.6.0_31\jre
Default locale: en_AU, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
c:\Data\dev\zlib\miniunzip>mvn -X compile
+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.6.0_20
Java home: C:\Program Files (x86)\Java\jdk1.6.0_20\jre
Default locale: en_AU, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "x86" Family: "windows"
We may also have a need to compile some modules to different JRE versions due to being a loaded library used in JRE 1.3/1.4/1.5/1.6
Is it possible to configure Maven POM to have profile differences or build differences based on the JRE version we are compiling to, or do we have to have 4 POM?
Is it possible to configure Maven to Run tests using an alternate JRE to that executing the Maven build?

Resources