Maven Glassfish plugin - Handling redeploy/deploy/undeploy Failure - pom.xml

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

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>

Related

Multi-module maven microservices deploy to Heroku

I have a microservices project with a parent POM and all the other modules with an internal POM.
Locally, if I run mvn clean install -DskipTests everything works.
I want to deploy all the microservices to Heroku, how can i do this?
The project works also for Docker & Kubernetes, is there a way to integrate also Docker in Heroku?
So it will be beautiful if I can deploy all the microservices as 1 project in Heroku, with every microservices as a Docker image.
Thank you in advance!
This is an example of my project:
Parent POM:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.petcare</groupId>
<artifactId>website-petcare-backend</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-pom</name>
<modules>
<module>apiGateway</module>
<module>reservationService</module>
<module>userService</module>
<module>eurekaServer</module>
<module>mapService</module>
<module>authService</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Build
You can build all images for the sub-modules using the docker-maven-plugin.
Each sub-module must have its own Dockerfile, then in the parent POM add:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.38.1</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
When running mvn clean package docker:build all projects are built and Dockerized
Deploy
Deploying all images (each image into its own web Dyno) is a little bit more complicated. You have few options:
Script from the command line: typically you can push the image with the following commands
heroku container:push web -a appname
heroku container:release web a appname
You could build a script that performs those steps for each and (very important) performs both the heroku login and heroku:container login using the credentials
Using heroku.yml where you can define at once all the containers to be deployed. It is a good approach but you need to git push your changes (see here)
Use CI/CD application like Github Actions. In this case your workflow compiles, tests, builds and pushes the application.
This is my preferred approach: you can decide when to build/deploy (on master push? manually?), you save the Heroku credentials as secrets, you can automate the release pipeline.
You can read more here
You can also try the Heroku Docker Maven plugin if you like to control all services using Maven

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy default-deploy on project

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project.
Failed to deploy artifacts: Could not transfer artifactReturn code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
There was no changes made since last successful build.
I double check settings.xml(username and password).Also check in pom.xml(distribution management)
I working on this issue since last 2 days.I gone through all the forum,nothing works.please help me out.
This error message means your machine is not authenticating correctly to the Nexus machine. The credentials sent to Nexus from Maven are not correct.
When I have gotten this message, I usually have to look in my settings.xml to verify the proper credentials in this part. The username and password have to be the right ones as set in Nexus itself.
<servers>
<server>
<id>nexus-releases</id>
<username>fillin</username>
<password>fillin</password>
</server>
</servers>
I usually go the Nexus GUI and try to log in with those credentials to verify them but it is possible to configure credentials that can publish via mvn but not log into the GUI.
One possible problem is if you are using dependency-management to identify where to deploy in case of "mvn deploy" target. There is a section like this:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>releases</name>
<url>http://myNexus/more/stuff</url>
</repository>
</distributionManagement>
and the id field has to match the the id on the credentials in the settings.xml. If the ids don't match, you will get this error.
Another possible problem is that if you are using an execution for the maven-deply-plugin in your pom.xml, you might have the configuration property
<repositoryId>nexus-releases</repositoryId>
and again it doesn't match the id in the settings.xml so it fails with your error.
Similarly, if deploying using the command line option on the "mvn" command that looks like this
-DrepositoryId=nexus-releases
doesn't match the id in the settings.xml, again, it won't work.
Following our discussion in the comments section,
try to run this pom.xml
When the mvn goal should be : mvn deploy
The only two things you need is having a pom and passing the arguments:
This is the pom.xml you can use:
<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>com.hp.Maven</groupId>
<artifactId>Maven-Nexus</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<properties>
<baseNexusURL>${baseNexusURL}</baseNexusURL>
<targetRepositoryID>${repositoryId}</targetRepositoryID>
<package.final.name>${project.artifactId}</package.final.name>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>deploy-node-modules-artifact</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${file}</file>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>${packaging}</packaging>
<generatePom>true</generatePom>
<repositoryId>${targetRepositoryID}</repositoryId>
<url>${baseNexusURL}/content/repositories/${targetRepositoryID}</url>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Jenkins Post Build Action: Deploy war to JBoss AS 7.x

I have Googled the following issue but not quite got what exactly to do as I am new to Jenkins. Here is one solution to this on SO itself, I can't comment on answer, due to low reputation.
How to deploy war file to jboss 7.1.1 from jenkins1.573 automatically during build?
It would be really great if somebody provides step by step way out of this:
Caused by: org.codehaus.cargo.util.CargoException: Cannot locate the JBoss connector classes! Make sure the required JBoss JARs (or Maven dependencies) are in CARGO's classpath.
More information on: http://cargo.codehaus.org/JBoss+Remote+Deployer
Edit Updated Pom.xml
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
</plugin>
</plugins>
</build>
If you use maven you can use maven jboss as plugin. Just add
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
</plugin>
<plugins>
</pluginManagement>
to your project's pom.xml
Then add as post-build step:
cd my-ear-or-war-packaged-project
mvn jboss-as:deploy -Djboss-as.port=9999 -Djboss-as.hostname=localhost
and the code should deploy in the post build step.
You can also add the execution of the plugin to a dedicated maven profile, which would make the artifact deploy already during the build phase, without the need to create additional build step in jenkins.

Does Xcode-Maven-Plugin can build iOS app on PC

I created a pom file for building iOS app. It can successfully build an iOS app on Mac. I searched online and I couldn't find a way to build the same pom file on PC. I just wanted to be sure that if it's possible to build the app on PC. I read that PhoneGap apps for iOS can be built on PC. So I thought it may possible to build my app on PC. Please bear with me if it's a silly question but unfortunately I couldn't find an obvious answer for that. Here is my POM file:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.package</groupId>
<artifactId>MyAppName</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>xcode-app</packaging>
<build>
<plugins>
<plugin>
<groupId>com.sap.prd.mobile.ios.mios</groupId>
<artifactId>xcode-maven-plugin</artifactId>
<version>1.14.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>package-xcode-project</id>
<phase>package</phase>
<goals>
<goal>package-xcodeproj</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
As far as I know, X-Code is only fully available on the Mac (OS-X), there exists no complete and supported environment on the PC.
So you should not try to build an environment there, furthermore the Maven plugin is only a build tool for combining and using available tools and adds version resolution mechanics to your build process and is not responsible for the compilers themselves.

Create pom.xml file

Could anayone give me some sugestions on how to create a pom.xml file for a multimodules project, that is build with ant? I need to create this pom.xml file in order to analyze the project with Sonar.
I suggest to follow the instructions from the Sonar documentation. See Analyzing Java Projects:
Project with multiple sources directories
If your non-maven project contains
more than one sources directory, you
can specify which sources directories
to analyse by adding a new section
about the Build Helper Maven Plugin
into your pom.xml file :
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[YOUR.ORGANIZATION]</groupId>
<artifactId>[YOUR.PROJECT]</artifactId>
<name>[YOUR PROJECT NAME]</name>
<version>[YOUR PROJECT VERSION]</version>
<build>
<sourceDirectory>[YOUR SOURCE DIRECTORY]</sourceDirectory>
<outputDirectory>[YOUR CLASSES/BIN DIRECTORY</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>[YOUR SOURCE DIRECTORY 2]</source>
<source>[YOUR SOURCE DIRECTORY 3]</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
<sonar.phase>generate-sources</sonar.phase>
</properties>
</project>
Replace the parameters :
...
And execute the maven2 plugin as explained in the installation guide :
mvn sonar:sonar
There is now a Sonar Ant Task that you can use, or there is also the Sonar Runner
What you put in the pom.xml is going to depend what dependencies you need to use and what plugins you need to run. Check out the Intro to POM to see what it is made up of.
I think you can try to use the builder-helper-maven-plugin, currently, latest version is 1.5.
as documented http://docs.codehaus.org/display/SONAR/Analyzing+Java+Projects. However, just change the plugin version to 1.5 and use mvn sonar3:sonar. Most importantly, dont forget <sonar.phase>generate-sources</sonar.phase>, without this, it doesn't work.
as for the output directory, if using eclipse, you can specify the output directory for each module, and make them point to the same folder. Use this folder as the outputdirectory for pom.xml. remember to disable scrub, if using eclipse.

Resources