Search code examples
mavenjettymaven-jetty-plugin

How to hot redeploy non-active maven project via jetty-maven-plugin


I'm trying to evaluate jetty for rapid development or project which is currently running on tomcat. My configuration looks like

        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.3.v20140905</version>
            <configuration>
                <scanIntervalSeconds>3</scanIntervalSeconds>
                <webApp>
                    <descriptor>${project.build.directory}/${project.build.finalName}/WEB-INF/web.xml</descriptor>
                    <resourceBases>
                        <directory>${basedir}/src/main/webapp</directory>
                        <directory>${basedir}/../SharedWeb/src/main/webapp</directory>
                    </resourceBases>
                    <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
                    <contextPath>/test</contextPath>
                </webApp>
            </configuration>
        </plugin>

I have main war depending on SharedWeb war via war overlay mechanism. I specify resourceBases for both maven projects so changes in resources are scanned automatically and reloaded on the fly and all working fine. Also when I compile classes in main war, jetty restarts automatically, reloading the latest changes. But when I try to change any class in SharedWeb project and compile it, the class is not reloaded. I'm just wondering if there is a way to make embed jetty to reload classes from SharedWeb automatically? I understand that jetty-maven-plugin uses SharedWeb war from local maven repository, so I need to install SharedWeb artifact before I can see any changes. So I don't have high expectations, but maybe I'm missing something.


Solution

  • Ivan,

    The plugin is using the classes and resources from your dependency war, NOT from the that you have added. The simply tells jetty to watch that location and redeploy if something in it changes - it does NOT put it onto the classpath.

    You need to tell jetty to use the classes and resources from your dependency war's project, NOT the war artifact.

    So do something like:

    <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.2.3.v20140905</version>
        <configuration>
            <webApp>
                <!-- tell jetty to use the classes from the dependency
    webapp project directly -->
                <extraClassPath>${basedir}/../SharedWeb/target/classes</extraClassPath>
    
               <!-- tell jetty to use both this project's static
    resources, and those of the dependency webapp project -->
               <resourceBases>
                   <directory>${basedir}/src/main/webapp</directory>
                   <directory>${basedir}/../SharedWeb/src/main/webapp</directory>
               </resourceBases>
            </webApp>
            <scanIntervalSeconds>3</scanIntervalSeconds>
           <!-- tell jetty to watch the dependency webapp project classes
    dir for changes -->
            <scanTargets>
                <scanTarget>${basedir}/../SharedWeb/target/classes/</scanTarget>
            </scanTargets>
        </configuration>
      </plugin>
    

    Jan