简体   繁体   中英

How Jetty plugin works for Maven?

I am pretty new in Maven and I am working on a portal developed with a product named Entando (but my question is not about Entando but it is about Maven).

So, into the documentation I find this statement about Maven:

Maven takes care of all the dependencies and thanks to the Jetty plugin it can also execute the portal without a DBMS and servlet container, which do not figure in the basic prerequisites for this reason.

So I know what Maven does and, reading the documentation, it seems to me that the Jetty plugin is a Maven plugin that simply scans the project for changes and automatically redeploys the webapp if any are found. This makes the development cycle more productive by eliminating the build and deploy steps.

Ok...this seems clear but what is meant by that it is used to execute the portal without a DBMS and servlet container?

I assume you quote the documentation of Entando .

Regarding Jetty it is a entire Webserver which can easely be runned as a embedded server. You will find various informations about jetty on their website: http://www.eclipse.org/jetty/

Especially interesting is the very good support of Jetty for Maven's standard directory layout described here: http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#configuring-your-webapp

Before giving you a final answer lets quickly have a sample on how easy you can use Jetty wihen working with a webapplication-project.

You can generate a webapplication from a maven archetype from the console like this (assumed you work with Windows and you have set the MAVEN_HOME-Variable and added it to the PATH-Variable, otherwise run it from where Maven is installed):

mvn archetype:generate -DgroupId=ch.jba -DartifactId=SampleWebApp -DarchetypeArtifactId=maven-archetype-webapp

You may have to hit Enter a few times to go with the default values (for example for the version).

Afterwards you will have a folder SampleWebApp within the directory you runned the above command. Inside this folder there is the pom.xml of the project as well as the /src folder.

(As a optional step you can import this project to your IDE - go for Java 1.7 which was the version i quickly verified it will work with the next step).

Now if you browse the files under src\\main\\webapp you will recognize (i guess so...) the standard webapplication directory-structure like for example described here: https://docs.oracle.com/javaee/6/tutorial/doc/bnadx.html .

Now there is the time where you could build this project by running the command mvn clean install - which will generate the so much wanted SampleWebApp.war archive under SampleWebApp\\target .

This is the time where Jetty kicks in if you dont want to setup a Webserver like Tomcat locally and still quickly run the example app. Just add the following right above </build> within your pom.xml :

<plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.2.11.v20150529</version> </plugin> </plugins> </build>

This adds the Jetty-Plugin (compatible with Java 1.7) to your Maven project and you are be able to run mvn jetty:run from the directory your pom.xml resides. When looking at the build-output you will recognize a few Exceptions like webAppSourceDirectory not set. Trying src\\main\\webapp webAppSourceDirectory not set. Trying src\\main\\webapp which is exactly the very good support of Jetty for Maven's standard directory layout i mentioned above.

After that you will see the sample project is deployed on Jetty and reachable under http://localhost:8080 (it will display Hellow World! or whatever else content you put into the index.jsp located under SampleWebApp\\src\\main\\webapp`.

Now to finally answer your question:

Have a look at this part of your quote:

it can also execute the portal without a DBMS and servlet container, which do not figure in the basic prerequisites for this reason.

It tells you that Entando (whatever that is... i for myself havent heard of it yet) does by purpose at the state you have read that quote not yet configured a DBMS or a servlet container to allow you to run it with Jetty in a easy way.

If you continue with the Tutorial/ Manual of Entando it will probably tell you on how to configure Jetty to work with a (embedded) DMBS (like H2-In-Memory-DB) and/or how to configure Jetty to work as a servlet container (so it supports HTTPServlet s as well).

=> Jetty is a dream to work with if you ask me - either to just quickly configure it inside your pom.xml , call/start the classes (and configure them) from within pure Java only or install it on your disk and use it from the command line as a standalone server (to be configured within its propertie-XMLs).

Note: Oftenly people forget about Jetty is not their final deployment environment and they just use it for a faster development process ... dont make that mistake and deploy your WAR to the final deployment environment (like Tomcat or whatever) from time to time.

Hope to have helped :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM