Reputation: 57323
Is there a way to run jetty 7 or 8 from ant? There's an ant plugin that works fine with the (pre-eclipse) version 6 only, but the eclipse versions seem only available in standalone form.
Upvotes: 2
Views: 727
Reputation: 8651
Quote from http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
Jetty has a slogan, "Don't deploy your application in Jetty, deploy Jetty in your application." What this means is that as an alternative to bundling your application as a standard WAR to be deployed in Jetty, Jetty is designed to be a software component that can be instantiated and used in a Java program just like any POJO. Put another way, running Jetty in embedded mode means putting an HTTP module into your application, rather than putting your application into an HTTP server.
This means that you can just add a single java class in your project, compile and run with something like:
<target name="run.jetty">
<java class="myjettyrun/RunJetty" classpathref="classpath.run.jetty"/>
</target>
And the RunJetty.java would look something like this:
package myjettyrun;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class RunJetty {
public static void main(String[] args) throws Exception {
Server server = new Server(80);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("distrib/wars/root.war");
server.setHandler(webapp);
server.start();
server.join();
}
}
This has been tested with Jetty 8. Make sure you have all the required jetty jars (jetty-webapps, jetty-server) and possibly jsp support (eg. jsp-2.1-glassfish) with their dependencies in classpath.run.jetty
.
In http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty you can find more examples on how to run jetty in different situations.
Upvotes: 2