2

Background
I am a Maven newbie and I greatly like the fact that Maven knows where to pick up all the JAR files needed for executing a Java program (i.e. the fact that the required JARs need not be specified in the CLASSPATH environment variable since they are all stored in the .m2 repository).

I thought Maven could be the preferred way to invoke Java programs for real world applications but for a previous post of mine the following comment was received:
If you want to execute java programs I would suggest to create self running artifacts instead of using maven to execute a program

This brings me to the following questions:


Questions

  1. Should using Maven as the tool for invoking Java programs be frowned upon?
  2. If yes (i.e. there are issues in using Maven as the preferred method for Java program invocation), what are the better alternatives and why?
Sandeep
  • 1,245
  • 1
  • 13
  • 33

1 Answers1

3

Maven is a build tool and was not designed to run programs.

If you want to test your program, your IDE should be enough to start it without any classpath hassle.

If you want give the program to someone else, use the Maven assembly plugin or the Maven shade plugin to bundle the jars with the dependencies. Then you can run it on any computer with Java installed.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142