Maven plug-in for consoles - automatic reboot using a multi-module project

I am developing a Java web application using the maven multi-module project. The project setup is as follows:

  • pom.xml The main maven project, which includes the following modules:
    • persistence: Entity Classes and DAO
    • business: Service definition and implementation
    • webapp: Apick wicket web application

The hierarchy of dependencies is as follows: webappdepends on business, which depends on persistence.

I also use Jetty Maven Plugin to run the web application locally using the mvn -pl webapp jetty:runmain directory inside. pom.xmlWhen developing the application, when making changes to the code, I want the berth server to reboot and reload the changed code files automatically. This works fine when I modify files inside a module webapp, but does not work when I modify a file inside another module, for example persistenceor business.

The Maven Jetty plugin is configured internally webapp/pom.xmlas follows:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.2.v20140723</version>
    <configuration>
        <reload>automatic</reload>
        <scanIntervalSeconds>1</scanIntervalSeconds>
        <webApp>
            <extraClasspath>../business/target/classes/;../persistence/target/classes/</extraClasspath>
        </webApp>
        <scanTargets>
            <scanTarget>../business/target/classes</scanTarget>
            <scanTarget>../persistence/target/classes</scanTarget>
        </scanTargets>
</plugin>

. <scanTarget> , jetty business persistence. <extraClasspath> , . <webAppConfig>. , <webApp>, ( <webAppConfig>, ).

: Jetty Maven , ?

+5
3

, . ,

mvn -pl webapp jetty:run

, extraClasspath. jetty:run webapp .


, scanTargets mvn -pl webapp jetty:run, ( ). Jetty :

[INFO] Added extra scan target:C:\PathToProject\business\target\classes
[INFO] Added extra scan target:C:\PathToProject\persistence\target\classes

<extraClasspath> <webApp>, org.eclipse.jetty.webapp.WebAppContext. , extraClasspath , .

+4

, .

1 -

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.plugin.version}</version>
    <configuration>
        <scanIntervalSeconds>${jetty.scanInterval}</scanIntervalSeconds>
        <scanTargets>
            <scanTarget>module-name/target/classes</scanTarget>
            <scanTarget>module-name2/target/classes</scanTarget>
        </scanTargets>
    </configuration>
</plugin>

2 - () RegEx , ,

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.plugin.version}</version>
    <configuration>
        <scanIntervalSeconds>${jetty.scanInterval}</scanIntervalSeconds>
        <scanTargetPatterns>
            <scanTargetPattern>
                <directory>${project.basedir}</directory>
                <includes>
                    <include>**/target/classes/**/*.class</include>
                </includes>
            </scanTargetPattern>
        </scanTargetPatterns>
    </configuration>
</plugin>
+4

The following configuration works for me

    <!-- To launch embded jetty server -->
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.4.2.v20110526</version>


    <configuration>
        <scanIntervalSeconds>3</scanIntervalSeconds>
        <webAppConfig>
            <contextPath>/${project.name}</contextPath>
            <extraClasspath>target/classes;../services/target/classes;../util/target/classes</extraClasspath>
        </webAppConfig>
        <scanTargets>
            <scanTarget>target/classes</scanTarget>
            <scanTarget>../services/target/classes</scanTarget>
            <scanTarget>../util/target/classes</scanTarget>
        </scanTargets>
    </configuration>

</plugin>
+3
source

All Articles