ipolevoy
ipolevoy

Reputation: 5518

Jetty warning "No resourceBase or war set for context" with Maven plugin

I use the jetty-maven-plugin with the following configuration:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.4.1.v20170120</version>
    <configuration>
        <jettyConfig>${basedir}/src/main/webapp/WEB-INF/development.jetty-config.xml</jettyConfig>
        <contextHandlers>
            <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                <contextPath>/</contextPath>
            </contextHandler>
        </contextHandlers>
        <reload>manual</reload>
        <scanIntervalSeconds>0</scanIntervalSeconds>
        <webApp>
            <contextPath>/</contextPath>
        </webApp>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
    </dependencies>
</plugin>

The file development.jetty-config.xml has the following contents:

<?xml version="1.0"?>
<Configure class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
    <Set name="resourceBase">./src/main/webapp</Set>
    <Set name="contextPath">/</Set>
    <Set name="war"><Property name="jetty.home" default="." />./src/main/webapp</Set>

    <New id="proj1DS" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg></Arg>
        <Arg>jdbc/proj1</Arg>
        <Arg>
            <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                <Set name="Url">jdbc:mysql://localhost/mydb</Set>
                <Set name="User">root</Set>
                <Set name="Password">***</Set>
                <Set name="UseUnicode">true</Set>
                <Set name="CharacterEncoding">UTF-8</Set>
            </New>
        </Arg>
    </New>
</Configure>

I then start Jetty with a Maven command:

mvn jetty:run

Relevant plugin logs:

[INFO] <<< jetty-maven-plugin:9.4.1.v20170120:run (default-cli) < test-compile @ proj1-admin <<<
[INFO] 
[INFO] --- jetty-maven-plugin:9.4.1.v20170120:run (default-cli) @ proj1-admin ---
2017-02-22 11:41:42.311:INFO::main: Logging initialized @3350ms to org.eclipse.jetty.util.log.StdErrLog
[INFO] Configuring Jetty for project: Proj Admin
[INFO] webAppSourceDirectory not set. Trying src/main/webapp
[INFO] Reload Mechanic: manual
[INFO] Classes = /home/igor/projects/Proj1/admin/target/classes
[INFO] Configuring Jetty from xml configuration file = /home/igor/projects/proj1/admin/src/main/webapp/WEB-INF/development.jetty-config.xml
[INFO] Context path = /
[INFO] Tmp directory = /home/igor/projects/proj1/admin/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:///home/igor/projects/proj1/admin/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = /home/igor/projects/proj1/admin/src/main/webapp
2017-02-22 11:41:42.449:INFO:oejs.Server:main: jetty-9.4.1.v20170120
2017-02-22 11:41:44.694:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=1975ms
2017-02-22 11:41:44.904:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2017-02-22 11:41:44.904:INFO:oejs.session:main: No SessionScavenger set, using defaults
2017-02-22 11:41:44.907:INFO:oejs.session:main: Scavenging every 600000ms

Then it prints this warning:

2017-02-22 11:41:47.150:INFO:oejsh.ContextHandler:main: Started o.e.j.m.p.JettyWebAppContext@26e412ef{/,file:///home/igor/projects/proj1/admin/src/main/webapp/,AVAILABLE}{file:///home/igor/projects/proj1/admin/src/main/webapp/}
2017-02-22 11:41:47.154:WARN:oejw.WebInfConfiguration:main: Can't generate resourceBase as part of webapp tmp dir name: java.lang.IllegalStateException: No resourceBase or war set for context
2017-02-22 11:41:47.155:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext@4ae263bf{/,null,null}
java.lang.IllegalStateException: No resourceBase or war set for context
    at org.eclipse.jetty.webapp.WebInfConfiguration.unpack(WebInfConfiguration.java:406)
    at org.eclipse.jetty.maven.plugin.MavenWebInfConfiguration.unpack(MavenWebInfConfiguration.java:135)
    at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure(WebInfConfiguration.java:72)
    at org.eclipse.jetty.maven.plugin.MavenWebInfConfiguration.preConfigure(MavenWebInfConfiguration.java:95)
    at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:501)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:539)
    at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:432)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
    at org.eclipse.jetty.server.Server.start(Server.java:452)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
    at org.eclipse.jetty.server.Server.doStart(Server.java:419)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:460)
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:328)
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:170)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)

To my surprize, the application loads and workig properly. In addition, the three lines in the config file:

<Set name="resourceBase">./src/main/webapp</Set>
<Set name="contextPath">/</Set>
<Set name="war"><Property name="jetty.home" default="."/>./src/main/webapp</Set>

do not have any effect, even if I delete them.

I looked at the docs, and these answers, but cannot figure it out:

How to deploy my web application to jetty9 as root application?

No hot deployment in Jetty 9.0.6

Jetty config without resourceBase

My questions are:

  1. How to properly configure this plugin to get rid of the warning?
  2. Should I be really worried since this is not an ERROR and the app is working?

Upvotes: 0

Views: 3526

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49545

Your setup is confusing.

Why are you configuring org.eclipse.jetty.maven.plugin.JettyWebAppContext via a Jetty IoC Context XML directly? Don't do that, its invalid.

You cannot change resourceBase from the jetty-maven-plugin, as the jetty-maven-plugin itself needs to control that setting for its own purposes.

The jetty-maven-plugin will use the information that exists in the maven subsystem to build out a list of resourceBases to make your webapp valid from the point of view of the Servlet spec and maven. It will pull in information from:

  • Your project's build (eg: defined output directories in your effective pom)
  • Your project's plugins (eg: dynamically assigned output directories from your plugins, such as from maven-resources-plugin, maven-compiler-plugin, maven-war-plugin, jspc-maven-plugin, etc)

From the point of view of Jetty proper, you cannot have a WebAppContext that defines BOTH resourceBase and war, they are the same thing, and have the same purpose.

  • resourceBase is the fundamental concept within Jetty (and is how the jetty-maven-plugin initializes your webapp)
  • war is the specialized resourceBase for the Servlet spec. (and only used when you have a proper *.war or expanded webapp deployable. this is not valid during jetty-maven-plugin execution)

For configuring contextPath, use the jetty-maven-plugin <configuration> instead.

If you have this Jetty IoC Context XML for the purposes of configuring a JNDI resource, consider just making it a normal configuration in your WEB-INF/jetty-env.xml file.

<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="proj1DS" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg></Arg>
        <Arg>jdbc/proj1</Arg>
        <Arg>
            <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                <Set name="Url">jdbc:mysql://localhost/mydb</Set>
                <Set name="User">root</Set>
                <Set name="Password">***</Set>
                <Set name="UseUnicode">true</Set>
                <Set name="CharacterEncoding">UTF-8</Set>
            </New>
        </Arg>
    </New>
</Configure>

Upvotes: 1

Related Questions