Open MehrabRahman opened 4 years ago
The first part (mvn) is how you start any mvn command in the terminal then the next part (exec) is a plug in used to run any of the main class generated in the target folder (com.example.App) the colon after exec allows for specifically stating the goal of where you want the program to execute so in this case with java it is within the same VM as maven
The -q is the quiet command. The intermediate output is silenced so you don't see all the inner workings. Instead you just see the final output.
The life cycle for maven involves default which handles the project build and deployment then clean which handles project cleaning and site which handles the creation of project site documentation so the exec command fits within the default part of the life cycle as does compile so you would want to compile then run the exec command then clean
exec
refers to the exec-maven-plugin, a plugin that allows maven to run programs and java classes. As a plugin, its functionality is supplied through "goals", of which exec has two: exec
for running system programs (possibly including java programs), and java
for executing java classes. Therefore, the colon specifies that the java
goal of the exec
plugin should be run. The -q
flag suppresses maven's output (not the Java class' output).
As it runs a compiled Java class, the command would fit between the compile
and package
phases. It would fit best on the test
phase so that any unit tests may be run before starting the class.
The command could be strung together with the clean and compile as mvn clean compile exec:java -q
to ensure that the newest version of the project is compiled before execution.
mvn exec:java -q is used by maven to execute the program in the main class by triggering the plugin responsible for this action.
mvn means that you are using a maven command. The exec command means you want to execute something. What you are executing comes after the colon, in this case a java program. The main class for the java program can be set in the pom.xml or you can use -Dexec.mainClass after the exec:java to set the main class. The -q means that there will not be any information shown about the execution except errors.
The command can be used after clean and compile to run the program. The clean command will remove the old compiled project, and you can recompile it with the compile command to make sure it is up to date.
the exec is a maven plugin that will execute a program that is specified after the colon, in this case a java program.
mvn specifies that this is a maven command. The exec command tells the maven project to execute the compiled code, and the java argument after the colon tells it to expect java code. The -q flag is an option to execute in quiet mode, so only necessary text will be printed to the console.
I would say that since this project is not finished, this will fall on the testing component of the maven lifecycle. You can chain it with the clean and compile commands to make sure the project is all properly compiled: mvn clean compile exec:java -q
The 'exec' plugin allows you to run goals, in which 'java' is one of them. Basically, the syntax tells you to call the plugin name, followed by a colon and the desired goal, which in this case, is 'java'. Maven needs to know which class you need to run, and which are the arguments if it is the case. We can achieve this by either adding this information into the pom.xml file through the 'plugins' tags and its subtags (
The "-q" argument will provide a quiet output not displaying any execution steps in the prompt-line except the errors if they occur.
You can also use these commands altogether with other options, goals, or phases invocations, like: "mvn clean compile exec:java" - that way, and following Maven lifecycle, it will clean the target folder and compiled build, compile class files into target/classes and run the Java class defined either at the pom.xml file or in the command line arguments.
According to the Readme, the command
mvn exec:java -q
will run our project. Break down the individual commands, arguments, and flags and explain their usage (i.e. what isexec
and why is it followed by a colon andjava
, or what is-q
).Explain where this command will fall on the Maven lifecycle, and how might we best combine it with the
clean
orcompile
commands.