List Info

Thread: Simplest way to load a custom RequestHandler in Jetty?




Simplest way to load a custom RequestHandler in Jetty?
user name
2006-08-29 01:25:25
For my Apachecon talk, I've created a few very simple
"demo"
RequestHandlers to show off some various functionality ... I
started
developing these in my solr SVN tree, so it wasn't untill
today that it
occured to me I had no idea what was needed in Jetty to add
an arbitrary
jar to the solr.war classpath at runtime.

My goal being to provide:
  * the java source
  * a precompiled jar
  * a solrconfig.xml that registers/refrences these
RequestHandlers
  * simple instructions for downloading a nightly build,
replacing the
    config, copying the jar to someplace magical, and
starting up the
    server.

(For me giving the talk, i could just compile the code right
into the
solr.war, or use Resin which I'm more familiar with -- but
i was hoping ot
have an easy way that anyone could recreate the my demo
using the default
example)

things I've already tried...

  * java -cp .:my.jar -jar start.jar
  * putting my.jar in the example/lib directory
  * putting my.jar in the example/ext directory (this has a
differnet
    problem - the jar is loaded before the webapp so it
can't resolve
    dependencies like "SolrRequestHandler")
  * modifing the jetty.xml to include something like this...
  <Call name="addWebApplication">
    <Arg>/hoss</Arg>
    <Arg>./webapps/solr.war</Arg>

    <Set
name="extractWAR">true</Set>
    <Set
name="defaultsDescriptor"><SystemProperty
name="jetty.home"
default="."/>/etc/webdefault.xml</Set>
    <Set
name="classLoaderJava2Compliant">false</Se
t>
    <Call name="addClassPath">
      <Arg><SystemProperty
name="jetty.home"
default="."/>my.jar</Arg>
    </Call>
  </Call>

  ...i got that last idea from here, based on the timeline,
this fix
should be in the Jetty5.1.11 that we're using, but it
doesn't seem to work
for me.


Has anyone out there gotten Jetty to load their custom
RequestHandlers,
Analyzers, or Similarities? ... even if you haven't do you
have any
suggestions on how to do it cleanly? (ie: without
deconstructing the war
and injecting my jar)

-Hoss

Simplest way to load a custom RequestHandler in Jetty?
user name
2006-08-29 02:50:47
On Aug 28, 2006, at 9:25 PM, Chris Hostetter wrote:
> things I've already tried...
>
>   * java -cp .:my.jar -jar start.jar
>   * putting my.jar in the example/lib directory
>   * putting my.jar in the example/ext directory (this
has a differnet
>     problem - the jar is loaded before the webapp so it
can't resolve
>     dependencies like "SolrRequestHandler")
>   * modifing the jetty.xml to include something like
this...
>   <Call name="addWebApplication">
>     <Arg>/hoss</Arg>
>     <Arg>./webapps/solr.war</Arg>
>
>     <Set
name="extractWAR">true</Set>
>     <Set
name="defaultsDescriptor"><SystemProperty 

> name="jetty.home"
default="."/>/etc/webdefault.xml</Set>
>     <Set
name="classLoaderJava2Compliant">false</Se
t>
>     <Call name="addClassPath">
>       <Arg><SystemProperty
name="jetty.home"
default="."/>my.jar</Arg>
>     </Call>
>   </Call>
>
>   ...i got that last idea from here, based on the
timeline, this fix
> should be in the Jetty5.1.11 that we're using, but it
doesn't seem  
> to work
> for me.

I don't think Jetty supports hot reload (correct me if I'm
wrong).   
You could pull this off with Tomcat though.  I did that kind
of stuff  
for lots of Tapestry talks with Tomcat running and setting
my IDE to  
compile classes right into WEB-INF/classes, waiting for the
context  
to reload and hitting refresh in the browser.

> Has anyone out there gotten Jetty to load their custom 

> RequestHandlers,
> Analyzers, or Similarities? ... even if you haven't do
you have any
> suggestions on how to do it cleanly? (ie: without
deconstructing  
> the war
> and injecting my jar)

Why not deconstruct the WAR?   Here's how I have my
development  
environment (and production too) set up with a little bit of
Ant, and  
solr.war checked into our repository as lib/solr.war.  It
only takes  
me a few seconds to go from saving a change to a .java file
to being  
up and running in Solr:

   <target name="unwar-solr">
     <unwar src="lib/solr.war"
dest="${build.dir}/solr"/>
     <copy
file="lib/lucene-similarity-2.1-dev.jar"
todir="$ 
{build.dir}/solr/WEB-INF/lib"/>
   </target>

   <target name="compile"
depends="unwar-solr">
     <mkdir dir="${build.dir}/classes"/>

     <javac
      srcdir="src/java"
      destdir="${build.dir}/classes"
      debug="on">
       <classpath>
         <path refid="classpath"/>
         <pathelement
location="${build.dir}/solr/WEB-INF/lib/lucene- 
core-nightly.jar"/>
       </classpath>
       <compilerarg
value="-Xlint:unchecked"/>
     </javac>


     <javac
      srcdir="src/solr"
     
destdir="${build.dir}/solr/WEB-INF/classes"
      debug="on">
       <classpath>
         <pathelement
location="${build.dir}/solr/WEB-INF/lib/classes"
/>
         <pathelement
location="${build.dir}/solr/WEB-INF/lib/lucene- 
core-nightly.jar"/>
         <pathelement
location="lib/lucene-similarity-2.1-dev.jar"/>
;
       </classpath>
     </javac>
   </target>

   <target name="dist"
depends="compile">
     <mkdir dir="${dist.dir}"/>

     <!-- this is our configuration directory -->
     <copy todir="${dist.dir}/solr">
       <fileset dir="solr"/>
     </copy>

     <!-- copy in the stuff just built -->
     <copy
todir="${dist.dir}/solr/webapps/solr">
       <fileset dir="${build.dir}/solr"/>
     </copy>
   </target>

Simplest way to load a custom RequestHandler in Jetty?
user name
2006-08-29 13:28:45
Erik Hatcher wrote:
  > Why not deconstruct the WAR?

Alternatively you can just update the WAR directly which is
what I'm doing to add in a 
custom TokenFilter I wrote:

<copy file="${lib.dir}/deploy/solr.war"
todir="${build.dir}"/>

<war destfile="${build.dir}/solr.war"
update="true">
   <lib dir="${build.dir}">
     <include name="icebox-solr.jar"/>
   </lib>
</war>

Here's the Jetty FAQ entry on Hot-Deploy:
http://jetty.mortbay.org/jetty5/faq/faq_s_
200-General_t_HotDeploy.html

Basically the raw Jetty doesn't have any Hot deployment
mechanisms built in, but it does 
hot deploy when embedded in other things (e.g. Jetty,
Geronimo).

-Andrew
Simplest way to load a custom RequestHandler in Jetty?
user name
2006-08-29 18:27:46
: I don't think Jetty supports hot reload (correct me if
I'm wrong).

I wasn't even trying to hot reload -- i just wanted a way
to specify in
the configs (before i start Jetty) that it should include my
extra jar in
the webapps classpath.

: > suggestions on how to do it cleanly? (ie: without
deconstructing
: > the war
: > and injecting my jar)
:
: Why not deconstruct the WAR?   Here's how I have my
development

don't get me wrong, i certainly can deconstruct/reconstruct
the war -- i
was just hoping for something simple that would show off how
easy it ease
to use custom request handlers in Solr ... but i'm
discovering it's not as
easy as i'm use to with Resin.


-Hoss

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )