17 February 2019

blog java

En utilisant l'option maven tomcat7:run-war, le war est compilé et lançé dans tomcat.

En substance, il faut pouvoir lancer la webapp avec les paramètres nécessaires pour la jvm et maven afin que Eclipse puisse connecter le debogeur.

Le conseil de la page est d'ajouter le plugin avec la configuration suivante :

<!-- Maven Tomcat7 plugin start -->
<plugin>
 <groupId>org.apache.tomcat.maven</groupId>
 <artifactId>tomcat7-maven-plugin</artifactId>
 <version>2.1</version>
 <configuration>
 <path>/${project.build.finalName}</path>
 <port>8080</port>
 <contextReloadable>true</contextReloadable>
 <systemProperties>
 <JAVA_OPTS>-Xms256m -Xmx1024m -XX:+DisableExplicitGC -Dcom.sun.management.jmxremote -XX:PermSize=256m -XX:MaxPermSize=512m</JAVA_OPTS>
 <MAVEN_OPTS>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000</MAVEN_OPTS>
 </systemProperties>
 </configuration>
 </plugin>
<!-- Maven Tomcat7 plugin end -->

Comme il se trouve que j'utilise déjà ce plugin, il dipose déjà de la configuration suivante :

      <!-- http://www.avajava.com/tutorials/lessons/how-do-i-deploy-a-maven-web-application-to-tomcat.html -->
      <!-- http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/usage.html -->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <url>http://localhost:8080/manager/text</url>
          <server>hnltomcat8</server>
        </configuration>
      </plugin>

La configuration devient donc :

      <!-- http://www.avajava.com/tutorials/lessons/how-do-i-deploy-a-maven-web-application-to-tomcat.html -->
      <!-- http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/usage.html -->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <url>http://localhost:8080/manager/text</url>
          <server>hnltomcat8</server>
           <path>/${project.build.finalName}</path>
 <port>8080</port>
 <contextReloadable>true</contextReloadable>
 <systemProperties>
 <JAVA_OPTS>-Xms256m -Xmx1024m -XX:+DisableExplicitGC -Dcom.sun.management.jmxremote -XX:PermSize=256m -XX:MaxPermSize=512m</JAVA_OPTS>
 <MAVEN_OPTS>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000</MAVEN_OPTS>
 </systemProperties>
        </configuration>
      </plugin>

Problème, cette configuration est chargée à chaque fois.

Je place cette configuration dans un profile déclenché par la présence de debug=true.