Deploy a jar to a wildfly server? - maven

I want to deploy an application packaged in a jar to a wildfly server after maven package phase, and before maven install.
I am using the following plugin in the project pom.xml:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.1.0.Beta1</version>
<configuration>
<hostname>127.0.0.1</hostname>
<port>9990</port>
</configuration>
</plugin>
how to configure this plugin execution?

You need the deploy goal of that plugin. It accepts a filename parameter which you could use to specify the application archive that you want to deploy.
Binding this goal to the deploy phase of Maven will not override other goals being invoked in that phase of the Maven lifecycle. They will continue to run.

Related

Deploying maven project to nexus server using git-describe plugin output

I have several maven projects that deploy to a nexus server. I don't like managing their versions via the pom file, and already use git tags for versioning via git-describe.
I added the git-describe maven plugin with the following config:
<plugin>
<groupId>com.lukegb.mojo</groupId>
<artifactId>gitdescribe-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>gitdescribe</goal>
</goals>
<id>git-describe</id>
<phase>initialize</phase>
<configuration>
<outputPrefix></outputPrefix>
</configuration>
</execution>
</executions>
</plugin>
and it works perfectly for mvn package runs - but when I use mvn deploy I end up seeing:
nexus/content/repositories/releases/me/botsko/project/${describe}/project-${describe}.jar
I tried to talk to the plugin author but it's been a few days and no reply.
How can I modify the plugin, or my configuration to property set the version during the deploy phase?
There may be a way to edit the plugin but I'm not familiar with how the maven plugin architecture works.
I solved the problem by writing a shell script that passes the same git-describe value to the maven deploy process:
#!/bin/sh
gitvers=`git describe`
mvn deploy -Ddescribe=$gitvers-SNAPSHOT
Just make sure you use <version>${describe}</version> or similar in the POM.

Exclude jar-with-dependencies from deploying to Nexus

I'm using maven-shade-plugin to create an additional jar with all my dependencies. The shade phase is linked to the package phase, so my jar-with-dependencies is created everytime I do a mvn package.
However, I do not want this jar-with-dependencies to be deployed to Nexus during mvn deploy. How can I avoid this?
The best solution for such purpose is to put the maven-shade-plugin configuration into a profile which is not activated during the deploy phase.
Driven by the same necessity I've forked the maven-deploy-plugin plugin from GitHub doing changes in order to exclude a specific attached artifact from deploy as follow:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-SNAPSHOT</version>
<configuration>
<skipAttachedArtifacts>
<artifact>
<groupId>com.sample</groupId>
<artifactId>something</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<classifier>shaded</classifier>
</artifact>
</skipAttachedArtifacts>
</configuration>
</plugin>
Currently using the maven-deploy-plugin plugin with skip parameter set to true all artifacts are excluded from deploy while target here is to exclude only a specific one from the attached ones. On my fork I've introduced the skipAttachedArtifacts configuration parameter in order to specify attached artifacts to exclude from deploy.
Here is the link on my forked project on GitHub:
https://github.com/gregorycallea/maven-deploy-plugin
Here the link instead to the pull request I've submitted on apache plugin project:
https://github.com/apache/maven-deploy-plugin/pull/3

How to 'mvn jetty:run' from a parent pom?

I have a multi-module project that includes several .war packages. I would like to be able to 'mvn jetty:run' on the parent pom and have each of the sub-modules's .wars deployed on the same embedded jetty instance.
I am able to successfully run 'mvn jetty:run' from each of the the sub-modules, but when I run it on the parent pom it fails and skips the sub-modules.
Trying to run 'mvn jetty:run' from the parent pom results in the following:
[ERROR] Failed to execute goal
org.mortbay.jetty:maven-jetty-plugin:6.1.16:run default-cli) on
project FlashCards_App: Webapp source directory C:\dev\sour
ce_code\FlashCards_App\src\main\webapp does not exist -> [Help 1]
It's true there is no webapp directory on the parent pom.
Here's an excerpt from my pom. The full file can be found here.
<modules>
<module>FlashCards_Domain</module>
<module>FlashCards_GWT</module>
<module>FlashCards_Service</module>
<module>FlashCards_Service_SpringData</module>
<module>FlashCards_Service_Jpa</module>
<module>FlashCards_WebServices</module>
<module>FlashCards_Struts</module>
<module>FlashCards_Test</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</build>
This is basically the same question asked in 2009 in this post. It's been a few years and I'm wondering if there are any other options available now. The previous post proposes two solutions (1) using cargo plugin and (2) building sister wars from a sub-module.
Your best shot is probably to configure the jetty plugin to run multiple webapps. I'm not sure if it would work from your parent pom though, so you might have to use on of your modules as the "launcher" webapp, or create a "dummy webapp" in your parent project.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.6.v20141205</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<webApp>
<contextPath>/</contextPath>
</webApp>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<war>${project.basedir}/app1/target/app1.war</war>
<contextPath>/app1</contextPath>
</contextHandler>
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<war>${project.basedir}/app2/target/app2.war</war>
<contextPath>/app2</contextPath>
</contextHandler>
</contextHandlers>
<stopPort>9999</stopPort>
<stopKey>STOP</stopKey>
</configuration>
</plugin>
cd parent_module
mvn jetty:run -pl sub_module
cd parent_module
mvn jetty:run -pl sub_module
To complete #jiahut answer:
$ mvn jetty:run --help
(...)
-am,--also-make If project list is specified, also
build projects required by the
list
-amd,--also-make-dependents If project list is specified, also
build projects that depend on
projects on the list
(...)
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path
Example from Apache Archiva:
mvn jetty:run -pl :archiva-webapp -am

Maven war plugin

Is it possible to have the maven war plugin output to two different locations? I currently have the following in my pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
This was already existing in the POM for the gwt maven archetype, and I'm guessing this explodes everything into the webappDirectory(which the gwt plugin then uses for it development mode).
When I do a
mvn war:war
It generate a war file for me in the target directory. So, I suspect its a different plugin configuration than the one in my POM (default behaviour?). How do I override this?
I basically want to accomplish the following:
I would like to have two different resource folders "src/resources/a" and "src/resources/b" , and have one of the folders used in the exploded version (currently in my pom) and the other version used when I do a "mvn war:war"
Per this question How to execute maven plugin execution directly from command line?, Maven doesn't use pom configuration when you invoke a plugin directly (e.g. mvn war:war). Your POM config is telling Maven to run the exploded goal when the compile phase is invoked (i.e when you run mvn [phase] where phase is compile or later).
I suggest you investigate using a separate profile for exploded deployment (called eg exploded), with a different configuration of the resources plugin to copy a different resources directory. Then use mvn compile -Pexploded for the exploded version.

Running antrun during war:exploded

For a Maven build I need to copy some files after the exploded directory has been made with the war plugin. Is it possible to run the antrun plugin during/after the war:exploded goal? If so how would I do this? I've tried:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>war</phase>
<goals>
<goal>exploded</goal>
</goals>
<configuration>
<tasks>
<echo>Running ant task...</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
And several other variation but can't seem to get it to run.
Idealy I'd like the ant task to run if I do a full war:war too but I'll cross this bridge when I come to it.
There are at least two ways to achieve it:
Using direct invocation of plugins
When calling mvn war:exploded oder mvn war:war, you only call a specific goal of a specific plugin. No other plugin is executed. Executions defined in pom.xml are not relevant. As a consequence, you could only call several plugin goals directly, for example mvn war:exploded antrun:run.
But be careful when building several modules: mvn war:exploded antrun:run runs antrun after the war plugin for each module. Whereas mvn war:exploded; mvn antrun:run runs the war plugin for all modules and then antrun for all modules.
Using lifecycle bindings of plugins
When calling mvn pre-integration-test, you call all phases of the default lifecycle up to pre-integration-test. You could define an war plugin execution for goal "exploded" in phase "package" and an antrun execution for goal "run" in phase "pre-integration-test".
There is no phase "war" in the default lifecycle. So your example above won't work with the default lifecycle. And for a custom lifecycle with custom phases, you need custom plugins.

Resources