1

I am able to successfully configure and start the embedded jetty using the jetty-maven-plugin configuration in the pom.xml like this,

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.version}</version>
    <configuration>
        <stopKey>webappStop</stopKey>
        <stopPort>9191</stopPort>
        <httpConnector>
          <host>localhost</host>
          <port>9090</port>
        </httpConnector>
    </configuration>
</plugin>

I can right click the project and run the maven goal, jetty:run and the project start running on port 9090,

[INFO] jetty-9.3.0.M1
[INFO] No Spring WebApplicationInitializer types detected on classpath
[INFO] Started ServerConnector@1023a4c5{HTTP/1.1,[http/1.1]}{localhost:9090}
[INFO] Started @8012ms
[INFO] Started Jetty Server

Now instead of right clicking and running the maven goal each time, I need to write an Ant task for the server start and stop commands.

Lucky
  • 16,787
  • 19
  • 117
  • 151

1 Answers1

2

Create the following simple build.xml and create two ant tasks to start and stop the server,

build.xml:

<project name="Demo Project" basedir=".">

  <path id="jetty.plugin.classpath">
    <fileset dir="jetty-lib" includes="*.jar"/>
  </path>

  <taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />

    <target name="jetty.run">
        <jetty.run />
    </target>

    <target name="jetty.stop">
        <jetty.stop />
    </target>

</project>

create a jetty-lib folder under the project root and place the following jars inside it,

javax.servlet-3.0.jar
jetty-ant-9.3.0.M1.jar
jetty-http-9.3.0.M1.jar
jetty-io-9.3.0.M1.jar
jetty-security-9.3.0.M1.jar
jetty-server-9.3.0.M1.jar
jetty-servlet-9.3.0.M1.jar
jetty-util-9.3.0.M1.jar
jetty-webapp-9.3.0.M1.jar

More about the configuration on the jetty-ant official documentation.

Lucky
  • 16,787
  • 19
  • 117
  • 151
  • 1
    Suggest you use an official/stable build of Jetty, not the Milestone. Use `9.3.5.v20151012` if you want the latest stable release. – Joakim Erdfelt Oct 14 '15 at 15:37
  • @JoakimErdfelt Thanks for the suggestion. I'll update my pom.xml and the jetty-lib *.jars too. But I'm unable to stop the server via ``. I can still see the port is open and throws me [Address already in use : bind exception](http://stackoverflow.com/q/12737293/1793718) if I run jetty-run after jetty-stop. Am I missing something? – Lucky Oct 15 '15 at 19:14