First application using Maven

Asked

Viewed 255 times

1

In my application I am trying to use Maven, but I have some problems that can be related to configuration, when I will generate a project JAR or use some Run As option from the pom.xml file in the terminal the return is always:

-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.

I am using jdk1.8.0_45, apache-Maven-3.3.3 and the following environment variables have already been added: JAVA_HOME and M2_HOME.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>appgeodev</groupId>
<artifactId>simple-map</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.3.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <finalName>simple-map</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

  • How are you M2_HOME and PATH?

  • M2_HOME looks like this: C: starcode apache-Maven-3.3.3 and PATH : ;%JAVA_HOME% bin;%M2_HOME% bin;

  • You’re running something with this is: -Dmaven.multiModuleProjectDirectory=$M2_HOME? As is windows, tried without the $?

  • @Brunocésar, I tried to execute this command in cmd with and without $ , as follows: mvn -Dmaven.multiModuleProjectDirectory=$M2_HOME, but unsuccessfully, the terminal returns me the following message: Please set the M2_HOME variable in your Environment to match the Location of the Maven installation

  • This way you put it will surely give error, because you are without any goal. Try, for example mvn clean -Dmaven.multiModuleProjectDirectory=$M2_HOME and update with the bug, tested in a windows here and is OK. If possible, include your pom.xml

  • @Brunocésar seems to be a problem in my configuration, because when I give the command mvn -version it shows me the following message on the terminal: ERROR: M2_HOME is set to an invalid directory. M2_HOME = "C program Files apache-Maven-3.0.4" Please set the M2_HOME variable in your Environment to match the Location of the Maven installation

  • I also could not run your suggested command, my pom.xml this very basic, nothing that should generate any problem

  • That value for M2_HOME It’s different from what I said before. See if the directory is correct, if it is configured right, without being in the user variables, etc.

  • That statement of "C program Files apache-Maven-3.0.4" is what the terminal, my M2_HOME path looks like: C: starcode apache-Maven-3.3.3, I’ll add my pom.xml

Show 4 more comments

2 answers

0

An alternative

In your eclipse access:

Window / Preference / Java / Installed Jres

Select the JRE and click Edit

On the field Default VM Arguments adds:

-Dmaven.multiModuleProjectDirectory=$M2_HOME

Obs.: You need to have Mave Home set.

0


Not to leave the topic without final answer, I ended up solving the problem by reinstalling the eclipse for the last version, apparently it was some problem with its installation because the Maven was installed correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.