Java – How does ‘maven jetty:run’ work

javajettymaven-3maven-plugin

what I have learned are:

  • Jetty is a java servlet
  • Maven is a build automation tool used primarily for Java projects
  • the jetty's url in github is https://github.com/eclipse/jetty.project
  • mvn jetty:run is run a web project from pom config
  • mvn jetty:run are supported by maven-jetty-plugin

So, next what should I do next?

And I want to know what happened when I execute the command mvn jetty:run?

What does it send to jetty when it has being used?

Best Answer

The run goal runs on a webapp that does not have to be built into a WAR. Instead, Jetty deploys the webapp from its sources. It looks for the constituent parts of a webapp in the Maven default project locations, although you can override these in the plugin configuration. For example, by default it looks for:

  • resources in ${project.basedir}/src/main/webapp
  • classes in ${project.build.outputDirectory}
  • web.xml in ${project.basedir}/src/main/webapp/WEB-INF/

The plugin automatically ensures the classes are rebuilt and up-to-date before deployment. If you change the source of a class and your IDE automatically compiles it in the background, the plugin picks up the changed class.

You do not need to assemble the webapp into a WAR, saving time during the development cycle. Once invoked, you can configure the plugin to run continuously, scanning for changes in the project and automatically performing a hot redeploy when necessary. Any changes you make are immediately reflected in the running instance of Jetty, letting you quickly jump from coding to testing, rather than going through the cycle of: code, compile, reassemble, redeploy, test.

https://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html#jetty-run-goal