Maven Glassfish plugin - Handling redeploy/deploy/undeploy Failure

2.1k Views Asked by At

I need to build and deploy the war into glassfish using maven(Problem explained below).

Currently I managed to deploy the war using maven glassfish plugin and I've used the goal redploy as shown in the POM below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>Myapp</groupId>
 <artifactId>Myapp</artifactId>
 <packaging>war</packaging>
 <version>1.0</version>
 <name>APP WEB APP</name>
 <url>http://maven.apache.org</url>

 <build>
  <finalName>MyApp</finalName>
  <plugins>
   <plugin>
    <groupId>org.glassfish.maven.plugin</groupId>
    <artifactId>maven-glassfish-plugin</artifactId>
    <configuration>
     <terse>false</terse>
     <echo>true</echo>
     <debug>true</debug>
     <glassfishDirectory>C:\glassfish3\glassfish</glassfishDirectory>
     <user>admin</user>
     <adminPassword>admin</adminPassword>
     <domain>
      <name>domain1</name>
      <host>localhost</host>
      <adminPort>4848</adminPort>
     </domain>
     <components>
      <component>
       <name>${project.artifactId}</name>
       <artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
      </component>
     </components>
    </configuration>
    <executions>
     <execution>
      <phase>install</phase>
      <goals>
       <goal>redeploy</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

</project>

Problem: say there is already a war deployed and when I execute the command mvn clean install and something goes wrong during the deployment.Since I've used the goal as redeploy the war would 1st do a undeploy and then do a deploy.In my case this POM cannot be used for the next time because there is a failure and the war does not exist.

Help required Please help me to achieve a check in POM whether the war is deployed or not and then based on the result I need to initiate goals deploy or undeploy which suites.

Say there is no war deployed i need to call glassfish:deploy in POM.

Thanks for your time in advance

1

There are 1 best solutions below

2
On

Found my answer Here:

Redeploy remote glassfish with cargo fails

No matter there is or isn't a war deployed the cargo plugin takes care of the above mentioned problem.

Main Catch is adding

<cargo.runtime.args>force=true</cargo.runtime.args>