0

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.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
Ivan Savchenko
  • 168
  • 2
  • 6

2 Answers2

1

Since there doesn't seem to be a good prior answer that is specific enough for this question (aka <scanTarget>) I'll just post this new one and tweak the title to make it easier to find in the future.

What you are looking for is <scanTarget>, as that will allow you to customize the scanning locations for changed content that will trigger a hot redeploy.

The jetty-maven-plugin intentionally does not set this up for custom <resourceBases> as there are far to many legitimate use cases where this can cause aggressive / too often / or infinite redeploys. It was decided that it was best to break from "convention over configuration" for <scanTarget> entries and allow the developers to decide what should be scanned for changes.

  <plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.3.v20140905</version>
    <configuration>
        ...
        <scanIntervalSeconds>3</scanIntervalSeconds>
        <scanTargets>
            <scanTarget>${basedir}/../SharedWeb/src/main/webapp/</scanTarget>
            <scanTarget>${basedir}/../SharedWeb/target/classes/</scanTarget>
        </scanTargets>
    </configuration>
  </plugin>
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Hm, I've tried this configuration (removed recoureBases) and I found that reload doesn't work for both resources and classes. When I change resource (like html) or recompile class (changing just method body), embed jetty is getting restarted and after restart it uses old resources and classes, which are probably taken from artefact from maven local repository. Could it be a bug or is it just something wrong with my project? – Ivan Savchenko Oct 01 '14 at 22:12
1

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

Jan
  • 1,287
  • 7
  • 7
  • OK this makes sense, but I don't see extraClassPath parameter in 9.2.3.v20140905 version of plugin. I checked documentation here http://www.eclipse.org/jetty/documentation/9.2.3.v20140905/jetty-maven-plugin.html Is this parameter have another name? Or is there another way to specify additional classpath? As I understand classesDirectory parameter is for dependent war, not the dependency one. – Ivan Savchenko Oct 02 '14 at 02:52
  • The beauty of the jetty-maven-plugin is that the is an instance of a subclass of o.e.j.webapp.WebAppContext. Therefore, you can invoke any of the single argument setters that exist on that class, or any of its superclasses. – Jan Oct 02 '14 at 03:15
  • Ah, it didn't work because of a typo: should be extraClasspath instead of extraClassPath. But it is working now, thank you for your help! – Ivan Savchenko Oct 02 '14 at 03:43