Jetty Annotation Timeout Reason
Asked Answered
F

6

29

I am tying to run my web application with maven jetty plugin. But after some time at startup, it gives the error:

[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
2014-08-10 17:39:45.840:INFO:oejs.Server:main: jetty-9.2.2.v20140723
2014-08-10 17:40:54.961:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext@1e2c8{/asd,file:/C:/dev/project/hope/target/asd-1.0/,STARTING}{C:\dev\project\hope\target\asd-1.0.war}
java.lang.Exception: Timeout scanning annotations
    at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.java:570)
    at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:440)
    at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:471)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1329)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497)
    at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:365)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)

I am using spring mvc with annotations and I think there is a problem about it.

When I try to run it over eclipse jetty plugin, it starts succesfully, but with maven plugin, it gives the error.

Any ideas?

Fluctuate answered 10/8, 2014 at 14:44 Comment(0)
P
48

I've got the same error and to fix it, you should add to your start script (start.ini) the following:

-Dorg.eclipse.jetty.annotations.maxWait=120

120 is for two minutes of annotation scanning in case that you need a higher value, just set it to the propper one.

Pomfrey answered 16/9, 2014 at 9:5 Comment(3)
how come some small project spend more time, and larger one without the -D still works? what exactly jetty is trying to do there?Religieuse
Sometimes the machine takes longer, high cpu usage because other OS processes or too many classes to parse.Pomfrey
You can reduce scanning jars to improve load speed, see my answerDingy
D
7

It is useless to scan all dependent jars, you can make the scanning pattern more restrictive to only match certain jars:

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.2.8.v20150217</version>
  <configuration>
    <webAppConfig>
      <contextPath>/</contextPath>
      <webInfIncludeJarPattern>.*/foo-[^/]*\.jar$|.*/classes/.*</webInfIncludeJarPattern>
    </webAppConfig>
  </configuration>
</plugin>

See webInfIncludeJarPattern doc for more details: http://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html#configuring-your-webapp

Dingy answered 2/6, 2017 at 2:20 Comment(2)
I don't understand what pattern I could use. How can I determine what jar/classes are needed. Somehow if maven put these jars in /lib they are needed. Few attempt to use this configuration lead to "ClassNotFoundException". any hint ?Johns
I would start with a pattern that matches nothing, like the word "none", and see if the application works without scanning. But if you're getting ClassNotFoundException, then take a look at the class name in the exception and try to identify which JAR file it comes from, then enable scanning for that JAR.Bligh
B
5

One more (in my opinion) convinient way is to set this property using a jetty.xml like so:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure>
    <Call name="setProperty" class="java.lang.System">
        <Arg>org.eclipse.jetty.annotations.maxWait</Arg>
        <Arg>120</Arg>
    </Call>
</Configure>

This way you can omit the commandline args

Blessed answered 6/5, 2017 at 11:9 Comment(3)
And how do i tell the plugin to use this jetty.xml?Merriment
@NathanBubna i think it looks in the current directory where you're running it, but im not sure. Best is to google itBlessed
@NathanBubna if you use Maven for your project then you could add "jetty.xml" file while configure jetty plugin in your pom.xml using <jettyXml> (read here eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html)Headlock
B
2

The most simple way is adding the system property in pom.xml

https://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html#setting-system-properties

Bornite answered 31/10, 2017 at 8:17 Comment(0)
I
0

This message means scanning annotation took time more than its being configured thus timeout so this can be fixed either by increasing the timeout period (Dorg.eclipse.jetty.annotations.maxWait=120) or by deleting the tmp / webapp-tmp from target which reduces its scan time.

Impressible answered 19/5, 2020 at 9:15 Comment(0)
M
-4

The property (-Dorg.eclipse.jetty.annotations.maxWait=120) can be added to start.ini so it works for all the webapps in your app base.

Mt answered 6/9, 2017 at 3:44 Comment(2)
Same above, look up!Fluctuate
My intention is to make it explicit on about the configuration file - start.ini. It is not obvious in the accepted answer.Mt

© 2022 - 2024 — McMap. All rights reserved.