Lucky
Lucky

Reputation: 17365

How to write an Ant task to start the embedded jetty in eclipse?

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.

Upvotes: 1

Views: 851

Answers (1)

Lucky
Lucky

Reputation: 17365

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.

Upvotes: 2

Related Questions