• How to add Maven Jetty Plugin

    Jetty is a Java Web Server which was developed by the Eclipse Foundation. Maven Jetty Plugin allows you to test, debug and deploy your web application without setting up a server.

    1. Add maven jetty plugin to your pom.xml

    Visit this post to create a simple maven web application if you don’t have one. In your pom.xml, add your maven jetty plugin in plugins under build section.

    
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        6.1.10
        
            <scanIntervalSeconds>10</scanIntervalSeconds>
            
                
                    8080
                    <maxIdleTime>60000</maxIdleTime>
                
            
            <stopKey>STOP</stopKey>
            <stopPort>8005</stopPort>
        
    
    

    You can change the default port of 8080 to something you want to avoid any conflicting port if you are running multiple instance of jetty. The final pom.xml should be something similar to this:

    
        
        <modelVersion>4.0.0</modelVersion>
        <groupId>SpringMVC4</groupId>
        <artifactId>SpringMVC4</artifactId>
        war
        1.0-SNAPSHOT
        SpringMVC4 Maven Webapp
        http://maven.apache.org
    
        
            1.8
        
        
            
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                3.8.1
                test
            
        
        
            <finalName>SpringMVC4</finalName>
            
                
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    3.0
                    
                        ${jdk.version}
                        ${jdk.version}
                    
                
                
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>maven-jetty-plugin</artifactId>
                    6.1.10
                    
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                        
                            
                                8080
                                <maxIdleTime>60000</maxIdleTime>
                            
                        
                        <stopKey>STOP</stopKey>
                        <stopPort>8005</stopPort>
                    
                
            
        
    
    

    2. Start Jetty

    To start jetty, in command line, navigate to your root project (where your pom.xml resides) and enter:

    mvn jetty:run

    You should be able to see something like this:
    jetty
    and test it to your browser by going to localhot:8080 or to the port that you have defined.

    Using IntelliJ, you can run maven jetty plugin by going into Maven Projects Tab and on Plugins section, double click jetty:run.
    maven jetty

    Related Post