Wildfly Maven Plugin ignores deployment name? - wildfly

I added the name parameter on my deployment using Wildfly Maven Plugin:
mvn wildfly:deploy -Dname=myapp -Dwildfly.hostname=myserver -Dwildfly.username=user -Dwildfly.password=pwd
However, it keeps on deploying with the Maven version and extension.
Here's how it looks in standalone.xml
<deployment name="myapp-1.1-SNAPSHOT.war" runtime-name="myapp-1.1-SNAPSHOT.war">
<content sha1="17e09de2cd8f78ffd033a90b4e82bdb52eb9485b"/>
</deployment>
The reason is to streamline the deployment process. After a Maven release, the deployment name changes to myapp-1.1.war, and the new development becomes myapp-1.2-SNAPSHOT.war. Instead of undeploying release myapp-1.1.war, and deploying myapp-1.2-SNAPSHOT.war, we want to reduce it to a single step - just redeploy myapp, and it should overwrite the old one.
Btw, if I just deploy, I'll have the two versions.
Just to be clear, this is the goal:
<deployment name="myapp" runtime-name="myapp-1.1-SNAPSHOT.war">
<content sha1="17e09de2cd8f78ffd033a90b4e82bdb52eb9485b"/>
</deployment>
This seems like a very simple case, and it should work as per the documentation: https://docs.jboss.org/wildfly/plugins/maven/latest/deploy-mojo.html

You can't override the name parameter on the via the command line. You'd need to add a configuration property for the name configuration parameter and override that on the command line.
...
<properties>
<deployment.name>${project.build.finalName}.${project.packaging}</deployment.name>
</properties>
...
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha7</version>
<configuration>
<name>${deployment.name}</name>
</configuration>
</plugin>
...
Then on the command you could use -Ddeployment.name=myapp. One note though is you'll want to use the appropriate file extension, e.g. .war, so the deployment will be processed properly.

Related

Possibility to access wildfly / app server libraries via jboss-deployment-structure.xml?

I have a web application running on a wildfly app server (22.X). It contains a war file which has the ability (besides the actual functionality) to query the wildfly itself for its active running sessions via JMX and display that number on an simple html page.
Originally the following dependency was added (via maven) to make this work:
<dependency>
<groupId>org.jboss.remotingjmx</groupId>
<artifactId>remoting-jmx</artifactId>
<version>3.0.4.Final</version>
However this dependency brings lots of other transitive dependencies along like jboss-marshalling, xnio, jboss-threads, wildfly-*, (...) - all packages which does exist within the wildfly app server anyway. So I was wondering whether it is possible to use those app server packages instead of bundling it as part of the war. I tried to add the following to the jboss-deployment-structure.xml to the EAR:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
<deployment>
<dependencies>
<system export="true">
<paths>
<path name="sun/reflect"/>
</paths>
</system>
</dependencies>
</deployment>
<sub-deployment name="service.war">
<dependencies>
<module name="org.jboss.remoting3.remoting-jmx" services="import"/>
</dependencies>
</sub-deployment>
However it didn't work - as soon as the dependencies were removed from the war file it stopped working. My question:
Is it possible to specify/configure the deployment structure file to allow access to the necessary packages from the application server? (I know that this is a wildfly specific solution but this is intended)
It looks like this module has moved to org.jboss.remoting-jmx. The org.jboss.remoting3.remoting-jmx does export the org.jboss.remoting-jmx module in WildFly 22, however the services are not exported which could be the issue.
Either way, it's best to use the org.jboss.remoting-jmx.

How can I choose a name for my application on OpenShift

I deployed my application on Openshift using the commands:
oc project <projectname>
Then I navigate to my application's directory and use the command:
mvn fabric8:deploy -Popenshift
This deploys to Openshift perfectly.
The only problem is that it automatically names my application and I am not sure where it is getting the name from. I want to change it to [app-name]-test, [app-name]-dev, etc
So, where does it get the application name from and how can I change it?
It's usually in your fabric8 XML configuration (pom.xml). For example:
<configuration>
<!-- Standard d-m-p configuration which defines how images are build, i.e. how the docker.tar is created -->
<images>
<image>
<name>${image.user}/${project.artifactId}:${project.version}</name>
<!-- "alias" is used to correlate to the containers in the pod spec -->
<alias>camel-service</alias>
<build>
<from>fabric8/java</from>
<assembly>
<basedir>/deployments</basedir>
<descriptorRef>artifact-with-dependencies</descriptorRef>
</assembly>
<env>
<JAVA_LIB_DIR>/deployments</JAVA_LIB_DIR>
<JAVA_MAIN_CLASS>org.apache.camel.cdi.Main</JAVA_MAIN_CLASS>
</env>
</build>
</image>
</images>
<!-- resources to be created -->
<resources>
<!-- Labels that are applied to all created objects -->
<labels>
<group>quickstarts</group>
</labels>
<!-- Definition of the ReplicationController / ReplicaSet. Any better name than "containers" ? -->
<deployment>
<!-- Name of the replication controller, which will have a sane default (container alisa, mvn coords, ..) -->
<!-- Override here -->
<name>${project.artifactId}</name>
...
It defaults to ${project.artifactId} but you can override with whatever you'd like with something like ${project.artifactId}-dev. You can also edit the deployment manually in Kubernetes:
$ kubectl edit deployment ${project.artifactId}

jboss 7 deployment issues with war

We are using jboss 7 and the jboss-as-maven-plugin to autodeploy our war files. We have a web.xml with the contextRoot set to our application name. In the plugin we configured our fileName to be ${project.build.finalName}.${project.packaging}. It deploys fine but the issue is when our war file name changes when we change our release number.
So for example The war changes from myproject-v1.0.1.war to myproject-v1.0.2.war when we get ready to release our next version. Issue is when the maven jboss plugin runs and tries to deploy the war file. Note We have force set to true so it should un-deploy the old application and deploy the new one.
The issue is it seems to key off of the war file name and not the webContext when determine if the application is currently deployed. So the new version fails to deploy because the old one is still running. We have to go in and manually un-deploy the previous version then re-depoly. It seems that the force un-deploy of the old app is based on the war name and since the version number changes it doesn't think its deployed and leaves the old version running. Which cause it to fail because the webContext is already used.
We attempted to change the config in the plugin to be generic and that works (the runtime name and name show this name and no longer the war file name). But the only issue is that seems to affect something on jboss and though it says its deployed the webContext isn't valid and we can't get to our application. Which is stranges since the webContext is set in the web.xml but it seems that the config in the plugin some how breaks it.
There is a name configuration attribute you can define. That should override the deployment name. If it's not set it does use the name of the file.
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.3.Final</version>
<configuration>
<name>your-app</name>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
So after playing with this for a while, we couldn't find any reason as to why when we used the config it would deploy but the webContext was not set. But when we manually deployed the same WAR it set the webContext.
So in the end. What we ended up doing was changing the name of the war to a generic name. So rather then myapp_v_1_0_1.war we made it myapp.war. This is a pain because now we don't know what version is deployed by just looking in the console. We need to hit the application which display the version number. But by doing this it solved our issue with un-deploying the old app, but created a new issue where its not as easy to determine the version deployed via the console.
This article seems to answer your question.
https://community.jboss.org/wiki/HowdoIoverridethewebcontextroot
I tried it on my own project and it works! Basically, create a jboss-web.xml (now your project is specific, so much for write once deploy anywhere). Make the jboss-web.xml look like...
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/rmbMavenCounter</context-root>
</jboss-web>
Remove the configuration from the pom.xml for the jboss-as-plugin. My plugin now looks like
<build>
<plugins>
.....
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
</plugin>
</plugins>
</build>
It will deploy with the snapshot name in the jboss admin console, but you can use the text string to access your application. For example, I used the following link to access the above application.
http://localhost:8080/rmbMavenCounter/
Here is the deployment from my jboss web server console...
08:12:42,413 INFO [org.jboss.as.server.deployment] (MSC service thread 1-16) JBAS015876: Starting deployment of "mavenCounter2-0.0.1-SNAPSHOT.war"
08:12:42,606 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Initializing Mojarra 2.1.5 (SNAPSHOT 20111202) for context '/rmbMavenCounter'
08:12:42,663 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Monitoring jndi:/default-host/rmbMavenCounter/WEB-INF/faces-config.xml for modifications
08:12:42,665 INFO [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /rmbMavenCounter
08:12:42,678 INFO [org.jboss.as.server] (management-handler-threads - 30) JBAS018559: Deployed "mavenCounter2-0.0.1-SNAPSHOT.war"
Same problem I faced: I wanted to upload the war using the version and build number for easy identification but at the same time to overwrite the previous service based on its name (with no version/build number).
This seems to be a limitation in the maven Jboss plugin: http://docs.jboss.org/jbossas/7/plugins/maven/latest/deploy-mojo.html. Currently only the 'name' parameter is supported which overwrites both the Name and the Runtime Name in the JBoss management console.
I would say long-term the plugin needs to support the 'runtimeName' as well in the list of parameters to the maven 'deploy' goal.
What you can do though, is to undeploy the service first using the 'undeploy' goal and use the 'matchPattern' parameter to find you previous service even if it included the version/build name.
Of course the disadvantage is that you have to undeploy; which is not well suited for a production environment.
For you example:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<port>${JBOSS_PORT}</port>
<username>${JBOSS_USERNAME}</username>
<password>${JBOSS_PASSWORD}</password>
<force>true</force>
<ignoreMissingDeployment>true</ignoreMissingDeployment>
</configuration>
<executions>
<execution>
<id>undeploy-MyProject</id>
<phase>install</phase>
<goals>
<goal>undeploy</goal>
</goals>
<configuration>
<hostname>${HOSTNAME}</hostname>
<matchPattern>myproject.*\.war</matchPattern>
</configuration>
</execution>
<execution>
<id>deploy-MyProject</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<hostname>${HOSTNAME}</hostname>
<name>myproject-${project.version}.war</name>
<filename>target/myproject-${project.version}.war</filename>
</configuration>
</execution>
</executions>
</plugin>

Change a file xml with maven plugin

I´m working with maven 3, migrating the old application using hivemind and ant. I need to change The file "Hivemodule.xml" with some properties with information about enviroment, I define with profile but it doesn´t work.
I try using maven-resources-plugin but without success, perhaps it just do with properties files.
Detail: The Hivemodule.xml is inside the file jar and I want to unpack this file to turn the content of internal hivemodule configurations and after, to pack again... I´m in the unpack fase.
Here is my file in Hivemodule.xml and the parameters that I want to turn:
PROVIDER_URL="ormi://localhost:23791/"
APPLICATION_NAME="services_1_11"
SECURITY_PRINCIPAL="oc4jadmin"
SECURITY_CREDENTIAL="welcome"
For use of profiles, I edited this file:
PROVIDER_URL="${PROVIDER_URL}"
APPLICATION_NAME="${APPLICATION_NAME}"
SECURITY_PRINCIPAL="${SECURITY_PRINCIPAL}"
SECURITY_CREDENTIAL="${SECURITY_CREDENTIAL}"
In my pom.xml, the references to profile:
<profiles>
<profile>
<id>local</id>
<properties>
<PROVIDER_URL>ormi://localhost:23791/</PROVIDER_URL>
<APPLICATION_NAME>services_1_11</APPLICATION_NAME>
<SECURITY_PRINCIPAL>oc4jadmin</SECURITY_PRINCIPAL>
<SECURITY_CREDENTIAL>welcome</SECURITY_CREDENTIAL>
</properties>
</profile>
</profiles>
And my resource configurations:
<resources>
<resource>
<directory>${serviceSegPath}/${serviceName}/META-INF/</directory>
<filtering>true</filtering>
</resource>
</resources>
Is there any suggestion to solution this? Another plugin to make changes in xml file?
Perhaps this profile is not active when running maven.
mvn -P local clean install

Maven assembly plugin: run only one descriptor

I have a project which has several custom descriptors written for the assembly plugin. Is there a way to run only one of those descriptors at a time instead of the whole bunch? I tried using the descriptors switch as documented here, passing in the full path to the one descriptor that I wanted to run, but instead it's running all of the descriptors in my app's main pom file, seeming to ignore the switch I specified.
Probably the easiest way to do so, is by using Maven Profiles.
Define some profiles in your pom.xml:
<profiles>
<profile>
<id>profile-1</id>
<properties>
<assembly-config>assem1.xml</assembly-config>
</properties>
</profile>
<profile>
<id>profile-2</id>
<properties>
<assembly-config>assem2.xml</assembly-config>
</properties>
</profile>
</profiles>
Then you use that particular property for the configuration of the assembly plugin:
...
<descriptor>src/main/assembly/${assembly-config}</descriptor>
...
Then run your maven build with the -P option: mvn -P profile-1 compile
So, summarized, if you choose a profile at buildtime, the property assembly-config will be set depending on the defined profile. The assembly configuration depends in that case on the chosen profile.
Hope this helps!