3

I'm trying to use mvn build command for a Maven project to generate a tar file.

When I run my Maven project in Eclipse through Run asMaven build, Eclipse can generate a tar file. But, the problem is when I used mvn build in command line, it says that unable to execute since mvn build is not a life cycle. So, can anyone say can we use mvn build through command line? Thank you in advance.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
krish
  • 349
  • 3
  • 17
  • Try with: mvn install – Joachim Rohde Jun 28 '16 at 15:52
  • @JoachimRohde I actually did it with mvn install. but i was asked to do that using mvn build. I searched rigorously in google but didn't found any answer. That's why i asked here to know whether mvn build can be used or not? – krish Jun 28 '16 at 15:59
  • If you are using "mvn install" 'install' is the goal that is called. The lifecycle that belongs to 'install' is "build" (see also https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html) Maybe a misunderstanding? I'm not aware of a goal named 'build' from the standard set. – Joachim Rohde Jun 28 '16 at 16:16
  • @JoachimRohde Thank you for the solution. – krish Jun 28 '16 at 16:23
  • It seems you are confused about the option "Maven Build" that you see in Eclipse. It does not run the command `mvn build` at all. I answered a question about the difference recently: http://stackoverflow.com/questions/37999457/what-is-the-difference-between-maven-install-and-maven-build-with-m2eclipse – Tunaki Jun 28 '16 at 17:12
  • @Tunaki. It helped. Thank you – krish Jun 28 '16 at 17:50

1 Answers1

0

If you want to use one of Maven's built-in lifecycles you have to invoke it with mvn <phase> inside your project's directory (where the POM [pom.xml] is located) on the command line. (And, as already commented, there is no phase called "build".)

Maven build is only available as a menu item of the M2Eclipse (m2e) plugin in Eclipse.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • `mvn` in the sense `mvn test` or `mvn install` like this right? – krish Jun 28 '16 at 16:26
  • @krishnapatamsetti Yes, depending on what you would like to achieve. See [this answer](http://stackoverflow.com/a/30953905/1744774) for how lifecycles, phases, etc. work together. – Gerold Broser Jun 28 '16 at 16:28