Jenkins maven target war - maven

on my laptop i'm using maven-war-plugin to build me a war file that I later deploy to tomcat
now i'm trying to recreate this build process with Jenkins and the problem that when i set a maven target as war it returns an error msg
[ERROR] Unknown lifecycle phase "war".
how can I use war plugin on jenkins build process ?

Usually, you don't call the war plugin directly, but you call mvn clean install on a project with packaging war. This will trigger all necessary steps, including compilation and also the war plugin.
So put in clean install in your Jenkins and this should be fine.

Related

Artifactory + TeamCity : How to deploy custom JAR?

I am building a maven project within a Docker container as a TeamCity job configuration.
(This is necessary because the maven project builds a JNA library -- so it must be built on a specific distro)
At the end of running the docker container, I'm left with the target folder of the maven module which contains the JAR & associated other files (i.e. class files etc..)
I'm stumped onto now how to get this JAR published to Artifactory? All the integration with TeamCity seems to be if the JAR was built with the maven runner specifically
Usually, you use mvn deploy to build and deploy an artifact with Maven. It is transferred to the Maven repository that you specified in your distributionManagement.
With Artifactory, you can also use the artifactory-maven-plugin for deployment.

Skipping deployment for some modules in an aggregate Maven POM

I have an aggregate Maven POM foobar that has several modules including foobar-api and foobar-web. The foobar-web POM actually creates a WAR file, and it uses the tomcat7-maven-plugin to deploy to Tomcat using the tomcat7:deploy goal.
If I bind the tomcat7:deploy goal to the deploy phase, I believe I could do a mvn clean deploy on the foobar-web project and have the WAR be automatically deployed to Tomcat. But if I were to do this on the foobar aggregate POM, wouldn't it complain with "Deployment failed: repository element was not specified in the POM inside distributionManagement element…"?
How could I turn off deployment for certain modules in an multi-module Maven project so that doing a mvn deploy on the aggregate POM would not fail on the non-web projects?
As an alternative, even if I don't bind the tomcat7:deploy goal to the deploy phase, how can I invoke the tomcat7:deploy goal on the aggregate POM and prevent an error for those modules that have no tomcat7-maven-plugin defined?
You probably confused maven deploy phase and goal deploy of tomcat7-maven-plugin.
Maven deploy is phase of maven build lifecycle which is intended to copy result artifacts to remote repository.
More info: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
tomcat7:deploy by default is bind to package phase, so if you don't chnge this setting, you can only deploy to tomacat by runing mvn clean package.
If you want stay tomcat7:deploy binding to deploy maven phase you can add in your modules
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
but this brake at all maven deployment of those module.

Spring Boot War

I tend to use the runnable JAR during development, but I need a WAR for deployment.
I've followed this article about converting from a JAR to WAR Spring Boot Gradle build.
However, right now, everytime I switch the builds from one to the other, I have to comment and uncomment the specific parts of the build file.
Is there a cleaner way of handling allowing for both a JAR and WAR build?
The war that gets build for deployment (that is if you added the spring-boot maven plugin) is just as runnable as a jar file.
java -jar mywar.war
And presto it starts with an embedded server, you can deploy the same war to your server and then it doesn't use an embedded server.
You can specify pom or gradle build file when you build.
So, you can create multiple pom files (one for jar packaging, the other for war packaging) for maven builds, also do same for gradle builds.
For example, if you setup pom.xml or build.gradle file for jar packaging and also setup pomWar.xml or buildWar.gradle for war packaging, then you can run below command
[ build jar packaging by maven ]
$ mvn clean install
[ build jar packaging by gradle ]
$ gradle clean test bootRepackage
[ build war packaging by maven ]
$ mvn -f pomWar.xml clean install
[ build war packaging by gradle ]
$ gradle -b buildWar.gradle clean test bootRepackage
war file can't be dependency of other project. so if you has other project has dependency on your spring boot project, then that is the case where you want to setup two different build files like above on your build machine

Where do maven jboss plugin deploy

I am using maven and jboss plugin. When I run this command
mvn clean install jboss-as:deploy
I will deploy in currently running jboss but I want to know which jar file it deploy..jar file generated in target folder or jar file in local repository?
By default it gets the bits from target folder. Look at targetDir property of the plugin.
You can find the details in the plugin documentation.

Using maven jetty plugin in multi-module project under Eclipse

I am working on a simple multi module maven project under Eclipse using m2eclipse with maven 3 and jetty plugin version 7. One of my module is a jar and the other module is a war which has a dependency on the jar.
Even though the workspace dependency resolution is enabled, the call to mvn jetty:run fails if I don't run mvn install before.
Having read about workspace dependency, I am not sure why a call to mvn install is required. I would like to be able to run the jetty plugin without installing the artifacts to my local repository. Is it possible?
Thanks in advance.
There is an integration module between m2eclipse and the WTP (Web Tool Platform).
WTP allow starting Jetty/Tomcat/... from Eclipse, debugging inside Eclipse, redeploy on change,...
Here is it: m2eclipse Extras

Resources