Jetty.project: A Quickstart-enabled war is served only "static" after first run (which generated Quickstart)

Created on 15 May 2017  路  20Comments  路  Source: eclipse/jetty.project

Hi,

I want to enabled my web-application with Jetty's Quickstart.

The Quickstart-module is already enabled in my Jetty. I am running a dedicated Jetty9.4.5.v20170502.
For starting, I have a ROOT.war, which dropped to jetty/webapps, just works fine. Additionally, I got jetty/webapps/ROOT.xml

<Configure class="org.eclipse.jetty.quickstart.QuickStartWebApp">
  <Set name="contextPath">/</Set>
  <Set name="war"><Property name="jetty.webapps" default="."/>/ROOT.war
  </Set>
</Configure>

Now, adding

<Set name="autoPreconfigure">true</Set>

to ROOT.xml, Quickstart will be generated.

2017-05-15 15:50:15.346:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=2341ms
2017-05-15 15:50:15.359:INFO:oejq.QuickStartDescriptorGenerator:main: Quickstart generating

When running Jetty again, the application/servlet will not be executed any more. Instead, a directory listing is shown to me at http://localhost:8080/

My application is a spring-boot application. I am NOT / cannot extend QuickStartWebApp at any point. But I can pre-generate the quickstart-web.xml by using PreconfigureQuickStartWar.
I am placing the ROOT.xml in webapps/, because, although I am pre-generating quickstart-web.xml, it seems only to be fetched, if ROOT.xml with autoPreconfigure=true is present.

I have attached the automatically generated jetty/webapps/ROOT/WEB-INF/quickstart-web.xml at pastebin (will expire at 2017-06-15).

Documentation

All 20 comments

What specific version of Jetty?

Version of Jetty is 9.4.5.v20170502 (I updated the issue, too).

Wait, you have ...

<Set name="war"><Property name="jetty.webapps" default="."/>/ROOT.war</Set>

.. specified, but the quickstart-web.xml is generated into an exploded directory at ...

jetty/webapps/ROOT/WEB-INF/quickstart-web.xml

Which form of webapp are you using? and which one do you want? (war or exploded directory)

I am starting with a fresh Jetty9.4.5 from download-page. I am enabling quickstart-module.

Afterwards, I am placing my ROOT.war and ROOT.xml in webapps/.

With quickstart module enabled, webapps/ROOT/ is generated by Jetty itself (I am guessing).

To me, the packing of my application is not important. I could start with dropping an exploded war in webapps/, too.

Start over.

Unpack your ROOT.war into webapps/ROOT
Do not have ROOT.war (as a war file) anywhere in your webapps/ directory.

Set your ROOT.xml to have the following war property

<Set name="war"><Property name="jetty.webapps" default="."/>/ROOT/</Set>

If you are happy with the results, I would recommend adding quickstart to your build of the war.
Then you can deploy the resulting ROOT.war

Note: you don't have to name it ROOT.war if you don't want to.
The <filename>.war can be any name you want if you also specify a similarly named <filename>.xml that has the contextPath set to /

<Set name="contextPath">/</Set>

I tried the approach, having only webapps/ROOT/, and not having webapps/ROOT.war

jetty-distribution-9.4.5.v20170502/webapps $ ls
README.TXT  ROOT  ROOT.xml

Plus, having webapps/ROOT.xml:

<Configure class="org.eclipse.jetty.quickstart.QuickStartWebApp">
  <Set name="autoPreconfigure">true</Set>
  <Set name="contextPath">/</Set>
  <Set name="war"><Property name="jetty.webapps" default="."/>/ROOT/</Set>
</Configure>

For testing, I added the quickstart-web.xml manually in my maven-project at src/main/webapp/WEB-INF, so it is finally at webapps/ROOT/WEB-INF/quickstart-web.xml.

Still no luck :-/ http://localhost:8080/ remains to show me directory listing of (some) contents auf webapps/ROOT/.

I am btw quite confused by the servlet-configuration at generated quickstart-web.xml. @joakime , do you think this is the way it shoud be?

@janbartel your thoughts?

@SchulteMarkus you should not need to pre-unpack your .war file: jetty will do that for you before it generates the quickstart-web.xml.

Can you confirm whether or not your webapp starts correctly the first time that it generates the quickstart, and fails on subsequent restarts? Or does it never work with quickstart, even the first time it generates?

Do you see any difference in the logging between when it starts up without quickstart, and when it starts up after quickstart?

Looking at the quickstart-web.xml that you provided, nothing sticks out as wrong. It looks a great deal like a test spring boot webapp that I have, which works when deployed as a .war with quickstart enabled, and works after the quickstart has been generated.

I think I'm going to need a small demonstration webapp from you to look into this further.

I changed from webapps/ROOT.war and /ROOT.xml to webapps/application.war and webapps/application.xml

The webapp starts correctly the first time (.war and .xml present, quickstart will be generated during this start, application-directory is being created during this start), and fails on subsequent restarts (using Quickstart).

From what I can see, there is a small difference in the logging. On the first start, it is

2017-05-16 08:19:26.564:INFO:oejsh.ContextHandler:main: Started o.e.j.q.QuickStartWebApp@67784306{/,[file:///home/markus-tarent/bin/jetty-distribution-9.4.5.v20170502/webapps/application, jar:file:///home/markus-tarent/bin/jetty-distribution-9.4.5.v20170502/webapps/application/WEB-INF/lib/springfox-swagger-ui-2.6.1.jar!/META-INF/resources],AVAILABLE}

, on the second, it is

2017-05-16 08:15:24.388:INFO:oejsh.ContextHandler:main: Started o.e.j.q.QuickStartWebApp@67784306{/,[file:///home/markus-tarent/bin/jetty-distribution-9.4.5.v20170502/webapps/application/, jar:file:///home/markus-tarent/bin/jetty-distribution-9.4.5.v20170502/webapps/application/WEB-INF/lib/springfox-swagger-ui-2.6.1.jar!/META-INF/resources],AVAILABLE}{/application/}

I uploaded both logs, first time log and quickstart log

@SchulteMarkus I'll have a look at those log files you sent.

It would be good if you could repost the generated quickstart-web.xml. And also can you please enable dumpAfterStart, and post the log output of both first run and subsequent runs please? You can do this by uncommenting and setting jetty.server.dumpAfterStart=true in start.d/server.ini file.

BTW you really should make a base dir for your webapp rather than running it at the top level $JETTY_HOME. See here for why: https://www.eclipse.org/jetty/documentation/9.4.5.v20170502/quickstart-running-jetty.html.

Regarding $JETTY_HOME - right now, I am only in a test-environment, for having rapid deployment. In the final environment, I am going to use jetty-docker-image.

Thank you so much for your help!

I'm having a different issue but it's quickstart related and it smells like there's a common root cause.

I've prepared a github repo with the webapp https://github.com/ffissore/jetty-quickstart-bug. It's a jersey webapp, serving 2 REST endpoints: you can run it with mvn jetty:run and connect to http://localhost:8080/app/hello/world.

Now try packing it in a docker image following the two sets of docker commands: the webapp will fail at startup with 2 different exceptions. The 2 context files used are in src/jetty

I think the NPE is related to a missing war property: I did so because I'm new to jetty configs and the doc doesn't mention it.

@SchulteMarkus try adding

 <Set name="generateOrigin">true</Set>

to your webapps/application.xml file.

Delete the unpacked webapps/application directory and run twice again. Does that help?

@janbartel
Yes, this helps

@SchulteMarkus excellent! I should have worked that out earlier - the spring boot should have rung some warning bells for me because it is related to this issue: #877 that I fixed recently ;)

@ffissore different problem. Your problem is that you've generated a quickstart-web.xml based on the maven classpath, and then tried to apply it in your docker image, where that classpath doesn't exist. See these lines from quickstart:

 <context-param>
    <param-name>org.eclipse.jetty.tlds</param-name>
    <param-value><![CDATA[
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/scriptfree.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/c.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/c-1_0-rt.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/fmt-1_0-rt.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/x-1_0-rt.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/permittedTaglibs.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/sql.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/sql-1_0-rt.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/c-1_1.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/fmt.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/fn.tld",
    "jar:${user.home.uri}/.m2/repository/org/apache/taglibs/taglibs-standard-impl/1.2.5/taglibs-standard-impl-1.2.5.jar!/META-INF/x.tld"]]></param-value>
  </context-param>

When generating quickstart from a jetty distro these file references point to $JETTY_HOME. However, when running with the maven plugin, all jars are obtained from the maven repo, hence the file references point to there.

Solutions are to either:

  1. install a maven repo in your docker image and keep using the maven plugin to generate the quickstart
    or
  2. generate your quickstart from a jetty distro instead so that the references will also be correct when running in docker
    or
  3. write the plugin we talked about to do a better job of generating the quickstart-web.xml :)

As @SchulteMarkus's issue is now resolved, I'm going to assign this to @WalkerWatch to make sure we document the issue with running spring web with quickstart.

Thank you @janbartel , when I compared the output of generated and pre-generated quickstart-web.xml I didn't notice the different path. Sorry for having polluted this issue. I'll try again coding that plugin

Was this page helpful?
0 / 5 - 0 ratings