Maven - Why after “mvn clean” I need to execute “Maven Update Project” before “mvn package”?

后端 未结 3 617
北荒
北荒 2020-12-31 11:34

I\'m making some tests and I would like to understand why after execute the command mvn clean I need to execute \"Maven > Update Project\" before run mvn

3条回答
  •  隐瞒了意图╮
    2020-12-31 12:02

    Here is what happens:

    1. mvn clean deletes the target directory
    2. mvn package performs some work, but then encounters a compilation error due to a missing dependency. That's why the target folder is in error.
    3. Running Maven > Update Project in Eclipse causes Eclipse to perform its own compilation, separate from Maven. Eclipse has a different classpath than Maven, so its compilation succeeds. Now the target directory has all the compiled classes.
    4. Re-running mvn package now succeeds, because it finds all the classes already compiled and doesn't need to perform any compilation.

    Ultimately, the problem is in the project configuration in pom.xml. I had the same problem, and after adding the missing dependency I successfully compiled project with Maven.

提交回复
热议问题