Domanda

I am developing a java application which currently runs in both jetty version 6(mortbay) and 8(eclipse) servers.

I find maintaining the project a bit hectic, due to the constant upgrades of versions now and then and would like to add integration tests that run in jetty's environment so i thought of integrating maven into it. I have already worked on a project that was maven based intially. I have been able to convert that project into a maven project and it seems to run perfectly as well.

The only issue is that i need to actually add context deployer to the maven's jetty plugin for one feature of my project. I compared mortbay's jetty.xml config file and eclipse's jetty.xml, and found that the mortbay's version contains the context deployer whereas there are no signs of the context deployer there and that configuration is specified in the jetty-contexts.xml.

I tried to change maven and jetty xml configs to see if it works.

This is the list of things i tried:

  1. Adding jetty-contexts.xml in pom.xml as follows:

    <plugin>
       <groupId>org.mortbay.jetty</groupId>
       <artifactId>jetty-maven-plugin</artifactId>
       <version>8.1.0.RC5</version>
           <configuration>
                <jettyConfig>jetty.xml</jettyConfig>
                <jettyConfig>jetty-contexts.xml</jettyConfig> 
       </configuration>
    </plugin>
    

    This gave the following error message: 2012-06-12 11:04:15.182:WARN:oejx.XmlConfiguration:Config error at java.lang.IllegalStateException: No object for id=DeploymentManager

  2. Then i tried to change the jetty.xml as follows:

    I read http://wiki.eclipse.org/Jetty/Feature/ContextDeployer and added the following config:

    <Ref id="DeploymentManager">
        <Call name="addAppProvider">
            <Arg>
                <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
                    <Set name="monitoredDir"><Property name="jetty.home" default="."/>/contexts</Set>
                    <Set name="scanInterval">1</Set>
                </New>
            </Arg>
        </Call>
    </Ref>
    

    This gave the same error message: 2012-06-12 11:04:15.182:WARN:oejx.XmlConfiguration:Config error at java.lang.IllegalStateException: No object for id=DeploymentManager

    so i changed it to:

    <Call name="addAppProvider">
        <Arg>
            <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
                <Set name="monitoredDir"><Property name="jetty.home" default="." />/contexts</Set>
                <Set name="scanInterval">1</Set>
            </New>
        </Arg>
    </Call>
    

    and this gave java.lang.ClassNotFoundException: org.eclipse.jetty.deploy.providers.ContextProvider

    In the above link, it is given that "The ContextProvider mechanism, which is now an extension of the core deployment infrastructure, implements this capability." So what i think is that i have to include some plugin for this functionality. Then I came across
    http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin#Using_GZip_Compression_and_Other_Jetty_Extensions

    This gave me the idea of how to add extra extensions. Then i found the jar containing ContextProvider in jetty-deploy jar.

    then added the following config in pom.xml:

    <plugin>
        <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.0.RC5</version>
    <dependencies>
        <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-deploy</artifactId>
        <version>8.1.0.RC5</version>
    </dependency>
    </dependencies>
        ...
    </plugin>
    

    This gives the following error: 2012-06-12 13:38:53.375:WARN:oejx.XmlConfiguration:Config error at <Call name="addAppProvider">... No Method: <Call name="addAppProvider"> on class org.mortbay.jetty.plugin.JettyServer

    Digging deep into the maven jetty plugin jar i found addLifeCycle method (deprecated) so i added following config (just like what is written in jetty 6 context file):

    <Call name="addLifeCycle">
        <Arg>
            <New id="hotdeployer" class="org.eclipse.jetty.deploy.providers.ContextProvider">
            <Set name="monitoredDir"><Property name="jetty.home" default="." />/contexts
                </Set>
            <Set name="scanInterval">1</Set>
            </New>
         </Arg>
    

    Maven jetty plugin started running after that. I created contexts folder under my project and added a context file and jetty throws the following error:

    java.lang.NullPointerException at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java :142) at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.ja va:53) at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:604) at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:535) at org.eclipse.jetty.util.Scanner.scan(Scanner.java:398)

    Looking at the source code, line 142 is _deploymentManager.addApp(app); which means that the deployment manager is null.

È stato utile?

Soluzione

I have finally found the answer. In pom.xml you have to add:

    <plugin>

            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.0.RC5</version>

            <dependencies>
                <dependency>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-deploy</artifactId>
                    <version>8.1.0.RC5</version>
                </dependency>
            </dependencies>

            <configuration>
                <webAppConfig>
                    <contextPath>XXXX</contextPath>
                </webAppConfig>
                <jettyConfig>jetty.xml</jettyConfig>
            </configuration>
     </plugin>

In jetty.xml you have to add:

    <Call name="addBean">
    <Arg><New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager"><Set name="contexts"><Ref id="Contexts" /></Set><Call name="setContextAttribute"><Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg><Arg>.*/servlet-api-[^/]*\.jar$</Arg></Call></New></Arg></Call>

<Ref id="DeploymentManager"><Call name="addAppProvider"><Arg><New class="org.eclipse.jetty.deploy.providers.ContextProvider"><Set name="monitoredDirName"><Property name="jetty.home" default="." />/contexts</Set><Set name="scanInterval">1</Set></New></Arg></Call></Ref>

Be careful of the spaces, maven jetty plugin complains about the spaces in the config of jetty.xml

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top