Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Advice about embedding Jetty into a large existing app


Shawn,

It's difficult to give a definitive answer to your questions because there are so many possibilities.  A couple of points:
  • When a jetty distribution is configured in XML, it is essentially just writing java code in XML that creates some objects, calls some setters, then calls the start method.  So anything that can be done in the distribution XML can be done in code.
  • LikeJettyXml is an embedded example that sets up pretty much the full server just as jetty.xml does.
  • The start.jar is a different matter, as it's job is to build a classpath and a list of XMLs to execute.  So you have to replace that by something  that will build your classpath (or a fat jar) and call a main method.   There are plugins for that kind of thing.  Things like lib/ext are really classpath stuff rather than config stuff.
  • You also might want to consider java 9/10/11 executable jars for this kind of thing.
It's not  really very difficult... other than there is perhaps too much flexibility so it can be hard to know which way to go.  My recommendation is to progress by:
  1. create a main method that initially just does hello world
  2. make the main method say "hello world "+some constant from a solr class
  3. Bundle up the main method and dependencies into an executable jar the way you want.
  4. Add "Server server = new Server(); server.start(); server.join();" to your main method
  5. Build on that by configuring the server in code until it does what you want.
cheers







On 17 May 2018 at 12:03, Shawn Heisey <eclipse@xxxxxxxxxxxx> wrote:
I'm from the Solr project.  This is a large application that currently ships with scripts that start Jetty to get Solr running.  I would like to have Solr be its own application.  The quickest path to that is to embed Jetty into Solr.

https://issues.apache.org/jira/browse/SOLR-6733

Some of the reasons for doing this are indirectly referenced here:

https://wiki.apache.org/solr/WhyNoWar

A little while ago I asked some questions on the freenode #jetty IRC channel.  Since it's evening in the USA as I write this, I am not expecting anyone on the channel to see what I've asked until tomorrow, so I thought I would move the discussion here.

Here's a transcript of my questions from IRC:

19:06 < elyograg> first big question: are there guides for doing this that I
                  can read?
19:09 < elyograg> I did find the "Embedding Jetty" section of the jetty docs,
                  and I will read that.  But I'm also interested in a quicklist
                  of dos and don'ts.
19:10 < elyograg> a question that's clearly NOT on-topic, but I need to ask
                  somewhere:  How do I go about creating solr-start.jar?  How
                  do I do this within an existing (and COMPLICATED) ant build
                  system?
19:13 < elyograg> when embedding jetty, do things associated with the full
                  jetty app (like lib/ext) disappear?  I would guess that they
                  do, just looking for confirmation.

Any advice?  I have read the 'Embedding Jetty' page now.  It looks like most of the meat of that is in the source code examples, which I haven't fully digested yet.

I think that all of Solr's handlers are accessed through a class that we call SolrDispatchFilter.

I'm sure I will have lots of really dumb questions once the work really gets underway.  I can do most of that on the IRC channel.

To anyone who might respond: If you'd prefer to use IRC, I'm there.  Can't guarantee that I'll be watching it, but I do have full access to the channel history once I get back to it.

Thanks,
Shawn

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--

Back to the top