`-Dmaven.multiModuleProjectDirectory not set` issue with Maven and IntelliJ - java

I've spent quite some time trying to figure out what I'm doing wrong and hoping someone may be able to help.
My current setup is running Maven 3.3.3 (via homebrew) and Java 1.8. IntelliJ 13 is the IDE of choice.
Running mvn -version results in the following:
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-
22T12:57:37+01:00)
Maven home: /usr/local/Cellar/maven/3.3.3/libexec
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"
which I believe means everything is OK, but when I go to my IDE and try to run a Maven project I get this error:
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java -Dmaven.home=/usr/local/Cellar/maven/3.3.3/libexec -Dclassworlds.conf=/usr/local/Cellar/maven/3.3.3/libexec/bin/m2.conf -Didea.launcher.port=7539 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13.app/bin" -Dfile.encoding=UTF-8 -classpath "/usr/local/Cellar/maven/3.3.3/libexec/boot/plexus-classworlds-2.5.2.jar:/Applications/IntelliJ IDEA 13.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.3
-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
Process finished with exit code 1
My M2_HOME var is set to /usr/local/Cellar/maven/3.3.3/libexec, the same directory where homebrew installed it, and this also matches the IDE settings.
One search lead me to believe it may be something to do with Maven version and the IDE but I'm not convinced. Can someone please shed some light on this please?

Just in case you have that error again go to Settings -> Maven -> Runner and add
-Dmaven.multiModuleProjectDirectory=$M2_HOME
to VM Options.

I had this wired issue while trying to build CAS Overlay Template using Maven. I could resolve it by adding the following environment variable:
MAVEN_OPTS = -Dmaven.multiModuleProjectDirectory

From the original question, the OP has solved their issue through this approach.
I upgraded to IDEA 14, imported settings, created a new Spring project and it worked out of the box.

Related

Maven is using wrong java version

I am trying to build a maven project on centOS 8. I want maven to use Java version 15. When I run mvn package I get the following error:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project systembrett-backend: Fatal error compiling: invalid target release: 15 -> [Help 1]
So I suspect that maven is using the wrong Java version, because when i do mvn package -X for debug logs it start with:
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_275, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.275.b01-1.el8_3.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-240.1.1.el8_3.x86_64", arch: "amd64", family: "unix"
so it looks like, maven is using Java version 1.8.
But mvn -version says:
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 15.0.2, vendor: AdoptOpenJDK, runtime: /opt/jdk-15.0.2+7
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-240.1.1.el8_3.x86_64", arch: "amd64", family: "unix"
JAVA_HOME is /opt/jdk-15.0.2+7 and PATH is /opt/jdk-15.0.2+7/bin:/home/username/.local/bin:/home/username/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin.
I thought maven is choosing the java version by checking JAVA_HOME, but apparently it is using an other version for the build. Does anyone know how to tell maven the correct version?
Thanks!
Following is a list of steps I use to troubleshoot this kind of issues:
Linux usually works with alternatives to ensure proper default Java environment is used. Similar to:
$ alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
+ 1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java)
* 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java)
Try also for javac as it may not be configured the same way:
$ alternatives --config javac
For your maven instance, JAVA_HOME should be enough.
Your output of mvn -version testifies that you have configured it correctly. Remove your Java from your PATH to ensure JAVA_HOME and mvn will find the correct one.
The pom.xml can also configure the required compiler, similar to:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Another thing may be that you're not using the same ENV (different terminals may not have the same environment variables exported - I presume you being on CentOS, you already encountered this). You have to exit the terminal and get back in to allow the default variables to take effect.
You encounter this usually when different JRE vs JDK are used ( more: maven installation has runtime as JRE instead of JDK )
I had the same issue on RHEL 9.1. The solution was to look at /etc/java/maven.conf and set the correct JAVA_HOME here in this file.

Error: Could not find or load main class $MAVEN_HOME

while running maven clean I am getting the following error :
Error: Could not find or load main class $MAVEN_HOME
while doing mvn -version I got :
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:4
7+05:30)
**Maven home: D:\mavenSecurity\apache-maven-3.3.9\bin\..**
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_79\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
I have set MAVEN_HOME = D:\mavenSecurity\apache-maven-3.3.9 in user variable in environment setting
Path in system variable in environment setting : D:\mavenSecurity\apache-maven-3.3.9\bin
Since I am getting other error previously so I have done the following also as mentioned in this post:
Eclipse error setting up Maven project for class exercise: Check $M2_HOME environment variable and mvn script match
-Dmaven.multiModuleProjectDirectory=$MAVEN_HOME
I have consulted other links but still I am getting the error while running MAVEN CLEAN in eclipse juno
This worked for me with the 3.3.9 version. The only difference is :
1) Add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder (Note: I have added it to system variables)
2) Update PATH variable, append Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere
Post output of mvn –version again if you face the issue. Also try running mvn clean from the command line and post the results.
configuring Maven on Eclipse. you have to tell eclipse where Maven has been installed so that it can use the Maven installation to build our projects.
Win 7 64 . Here is how i did my config.

Change JDK in IntelliJ seems not working

I'm on Windows, I've already set the Path to JDK 1.8 in Environment Variables.
Also in Project Structure, I've already changed to it. I have a Maven project.
On command line, if I use `mvn --version' I see
Apache Maven 3.0.4 (r1232337; 2012-01-17 15:44:56+0700)
Maven home: C:\apache-maven-3.0.4
Java version: 1.8.0_77, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_77\jre
Default locale: en_AU, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
However, in IntelliJ, if I hit the Run button, it always points to JDK 1.7, and an error is thrown (since my maven project requires java 8). How do I change that? Thanks
"C:\Program Files\Java\jdk1.7.0_09\bin\java" -Xms512m -Xmx1024m -Dclassworlds.conf=C:\apache-maven-3.0.4\bin\m2.conf -Dmaven.home=C:\apache-maven-3.0.4 -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\apache-maven-3.0.4\boot\plexus-classworlds-2.4.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher --no-plugin-registry --fail-fast --strict-checksums --update-snapshots -f C:\Users\Tung\server-pinbike\api-pinbike2\pom.xml install
Update
After following #BevyQ tip, I found that the JRE of Maven runner was pointing to Jre7, that's the reason.
See screenshot below, hope it helps someone.
Have you checked your modules settings?
In Project Structure, click Modules->"Your modules"->Dependencies to see what SDK you are using.
And you should check the Run configurations too.
I am able to repo your scenario by setting the Project SDK to 1.7 then set them module SDK to 1.8.
The version you got by using commend line, is the version that windows is using. It doesn't mean that version is applying to you project or your module in IntelliJ.
So, please double check if you set both project and module's SDK to 1.8.
Below are some screen shots of my repo.
I set module SDK to 1.8. And set Project SDK to 1.7
Mvn version is 1.8. But it will using 1.7 when I run the project

Perform command does not work in Spring Roo

When running the 'perform tests' command in Roo I get the following error:
createprocess error=2,the system cannot find the file specified.
Now, all the posts on the net suggest that maven should be in PATH. I did that, I rebooted, my maven installation path is in there along with my roo path and java path. I have ROO_HOME set, JAVA_HOME and M2_HOME.
The versions I use are:
Maven: 3.3.1
Roo: 1.3.1.RC1
Java: 1.8.0_45
When I run Maven from the commandline i get this:
X:\...>mvn -v
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T21:10:27+01:00)
Maven home: X:\apache-maven-3.3.1
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: X:\Java\jdk1.8.0_45\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
Maven seems to be fully functional.
I also can start the roo console from the commandline:
X:\...> roo
1.3.1.RC1 [rev 4877cfb]
Welcome to Spring Roo. For assistance press CTRL+SPACE or type "hint" then hit ENTER.
roo> perform tests
CreateProcess error=2, The system cannot find the file specified
roo>
So my question is, does anybody know if this is a bug? Because I'm under the serious impression that it is. Posts that 'supposedly' solve this problem are 2y or older.
Thanks for the help!
Got the same problem.
Roo is searching for mvn.bat file in the maven's bin directory, but in the version 3.3.1, there is mvn.cmd only.
Try either renaming the mvn.cmd to mvn.bat in your maven bin directory (worked for me), or use older version of maven, for example 3.0.4.
Thanks for the suggestion! Instead of renaming though, if you use a recent version of Windows (10 in my case) you can create a symlink as well. Open admin command prompt > navigate to your maven bin folder > and execute the command:
mklink mvn.bat mvn.cmd
hint: I also do this if I need to swtich between maven versions, pointing my m2_home to a symlink and just switching the symlink when needed to point to the right place.

${java.home} changes when running Maven on a OS X

This appears to be a problem I do not see on linux or Windows machines. I have my environment setup with a JAVA_HOME derived from /usr/libexec/java_home. This is in my .bashrc file:
export JAVA_HOME=$(/usr/libexec/java_home -version 1.7)
which results in:
~/dev/Endeavor/endeavor-sdk$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
However when I run Maven on my project, I get an error from the native2ascii plugin:
[ERROR] Failed to execute goal org.codehaus.mojo:native2ascii-maven-plugin:1.0-alpha-2-SNAPSHOT:native2ascii (default) on project dataAccessServices: Error starting Sun's native2ascii: -> [Help 1]
My investigation points to that I am using a JRE instead of a JDK. That's odd since I am clearly pointing to the JDK in my JAVA_HOME variable. However, here is the output of mvn -version:
~/dev/Endeavor/endeavor-sdk$ mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
Maven home: /usr/share/maven
Java version: 1.7.0_17, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.5", arch: "x86_64", family: "mac"
Notice the "Java home:" line indicates that the ${java.home} variable has been moved to the JRE instead of the JDK that the JAVA_HOME environment variable points to.
I have tried setting the JAVA_HOME in numerous places but I can't seem to find a way to get maven to use the JDK as the home and not the JRE.
UPDATE:
I found this that appears to indicate that this is expected behavior: Java_home in Maven
But that does not explain why the native2ascii plugin cannot find the JDK tool it needs.
I have removed the use of native2ascii since it was largely unnecessary. So, I am avoiding the problem at this point. However, if anyone has an idea as to why this behaves differently on different systems, please let me know.
Have you tried running mvm help:system that should print all environment variable values that are relevant to maven?
There has been lots of discussions on this matter and here Java_home in Maven you can find a real good answer.
In a nutshell: your configuration it's just right, it is just a matter of semantics. You can read further here: http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html

Categories

Resources