Jump to: navigation, search

Difference between revisions of "Jetty/Howto/Use Jetty with Ant"

< Jetty‎ | Howto
m
m
Line 6: Line 6:
  
 
Modifying build.xml from jetty-ant-demo is also the easiest way to start playing with this plugin.
 
Modifying build.xml from jetty-ant-demo is also the easiest way to start playing with this plugin.
 
+
}}
 
==Beginning To Use Ant==
 
==Beginning To Use Ant==
  
Line 183: Line 183:
 
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
 
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
 
* ''connectors'' - specifies additional web application connectors
 
* ''connectors'' - specifies additional web application connectors
}}
 

Revision as of 12:04, 21 September 2010



Introduction

{{{introduction}}}

Beginning To Use Ant

The Ant plugin depends on Jetty JARs, and so far it's necessary to build Jetty and then the Ant plugin directly from sources. Here's how it goes:

  1. Get the latest jetty sources from http://dist.codehaus.org/jetty/
  2. Unpack jetty and build it with 'mvn install' (If you don't have Maven yet, get it from http://maven.apache.org/)
  3. Go to the extras/ant/ folder and build ant plugin with 'mvn install'
  4. Go to <your M2 repo root>/repository/org/eclipse/jetty/jetty-ant and grab the jetty-ant plugin JAR.
  5. Get these files to run Jetty with JSP/Servlets support (find these in <your M2 repo root>/repository/org/eclipse/jetty):
    • jetty.jar
    • jetty-util.jar
    • jetty-plus.jar
    • jetty-naming.jar
    • servlet-api-2.5.jar
    • jsp-api-2.1.jar
    • jsp-2.1.jar
    • and core-3.1.1.jar from <M2 repository>/org/eclipse/jdt/core/3.1.1/
  6. Put all the JARs inside one lib directory (let's say jetty-lib).

Preparing the build.xml file

Let's start with an empty build.xml

<project name="Jetty-Ant integration test" basedir=".">
</project>
Then, you must define a jetty task: 
<project name="Jetty-Ant integration test" basedir=".">
  <path id="jetty.plugin.classpath">
     <fileset dir="jetty-lib" includes="*.jar"/>
  </path>
  <taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
</project>

Now, we are ready to add a new target with Jetty container declaration:

<project name="Jetty-Ant integration test" 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 />
  </target>
</project>

Starting jetty on port 8080 is then a simple matter of executing ant jetty.run from the command line.

Deploying web applications

Adding web applications to the Jetty web server is now a simple matter of putting extra webapp tags inside jetty tag. Notice, that a tempDirectory attribute has been added to the jetty task to specify where temporary files are stored.

 
<project name="Jetty-Ant integration test" 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 tempDirectory="jetty-temp">
      <webApp name="webapp1" warfile="webapp1.war" contextpath="/webapp1" />
    </jetty>
  </target>
</project>

You can put many webapp tags inside jetty tag, thus deploying many web applications simultaneously.

Plugin syntax

There are many ways to configure jetty task:

  • tempDirectory - specifies the Jetty temporary web directory:
<jetty tempDirectory="jetty-temp" />




  • requestLog - defines a request logger:
<jetty ... requestLog="your.fancy.request.logger"/>




  • jettyXml - applies additional configuration via a standard jetty.xml file:
<jetty ... jettyXml="path/to/jetty.xml"/>




  • systemProperties - adds system properties when starting Jetty:
<jetty ...>
  <systemProperties>
    <systemProperty name="jetty.status" value="Jetty Rocks!"/>
  </systemProperties>
</jetty>




<typedef name="selectChannelConnector" classname="org.mortbay.jetty.nio.SelectChannelConnector"
                           classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
...
<jetty ...>
  <connectors>
    <selectChannelConnector port="8090" />
  </connectors>
</jetty>







<typedef name="jdbcRealm" classname="org.mortbay.jetty.security.HashUserRealm"
                 classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
...
<jetty ...>
  <userRealms>
    <userRealm name="realm1" config="path/to/realm/config" />
  </userRealms>
</jetty>







There are also many ways to configure web applications with webapp tag:

<jetty ...>
  <webapp name="name" .../>
</jetty>




<jetty ...>
  <webapp warfile="/path/to/war/file/or/web/application/contents" .../>
</jetty>




<jetty ...>
  <webapp contextPath="/webapp" .../>
</jetty>




<jetty ...>
  <webapp jettyEnvXml="/path/to/jettyEnv.xml" .../>
</jetty>




<jetty ...>
  <webapp webXmlFile="/path/to/web/xml" .../>
</jetty>




<jetty ...>
  <webapp ... scanIntervalSeconds="5">
    <scanTargets dir="path/to/included/resources">
      <include name="filename/patterns" />
    </scanTargets>
  </webapp>
</jetty>




<jetty ...>
  <webapp ...>
    <lib dir="path/to/jar/folder" includes="*.jar" excludes="not-needed.jar" />
  </webapp>
</jetty>




<jetty ...>
  <webapp ...>
    <classes dir="path/to/classes/folder" includes="*.class" />
  </webapp>
</jetty>




Retrieved from "http://wiki.eclipse.org/index.php?title=Jetty/Howto/Use_Jetty_with_Ant&oldid=220864"