Hi,

As part of the demo we will see how to execute the WildFLy jboss-cli.sh task using maven plugin. This demo will be useful for the developers who are more comfortable with Maven and wants to accomplish general monitoring/configuration tasks on WildFly 10 using the Maven based approach. We can execute any CLI command from the below mentioned maven task.

In this demo we will see how to monitor the EJB3 subsystem details using maven based approach which internally invokes the “jboss-cli.sh” script.   (Java 8 is needed to run this demo on WildFly 10 see bottom of this article.)

Step-1). Create a directory somewhere in your filesystem to place the “test.cli” WildFLy script and the maven based “pom.xml”.

  $ mkdir Running_CLI_Using_Maven
  $ cd Running_CLI_Using_Maven

Step-2). Create a simple “Running_CLI_Using_Maven/test.cli” script as following (We can have any kind of JBoss CLI command inside this script file, Like creating DataSource, deploying/undeploying applications ..etc)

    /subsystem=ejb3/:read-resource(include-runtime=true)

Step-3). Now the main part is to write a simple Maven based “Running_CLI_Using_Maven/pom.xml” file as following:

<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>middleware.magic</groupId>
	<artifactId>RunningCLI_ViaMaven</artifactId>
	<packaging>jar</packaging>
	<version>1.0</version>
	
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <wildfly.home>/PATH/TO//wildfly-10.0.0.CR3-SNAPSHOT</wildfly.home> <!-- CHANGE ME !!! -->
        <wildfly.hostname>localhost</wildfly.hostname>   <!-- CHANGE ME !!! -->
        <wildfly.user>admin</wildfly.user>  <!-- CHANGE ME !!! -->
        <wildfly.pass>admin@123</wildfly.pass>  <!-- CHANGE ME !!! -->
        <wildfly.port>9990</wildfly.port>  <!-- CHANGE ME !!! -->
    </properties>

	<build>
          <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!-- http://ant-contrib.sourceforge.net/
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath" /> -->
                                <exec dir="${basedir}" executable="${wildfly.home}/bin/jboss-cli.sh" failonerror="true">
                                  <arg line="--controller=${wildfly.hostname}:${wildfly.port} --user=${wildfly.user} --password=${wildfly.pass} -c file=${basedir}/test.cli" />
                                </exec>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                
                <dependencies>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>20020829</version>
                    </dependency>
                </dependencies>
            </plugin>

	 </plugins>
     </build>
</project>

Step-4). Now we will run the maven project as following (please make sure to start the WildFly first). Open a terminal and then set the following variables. We can run the following command: “mvn antrun:run”

$ export M2_HOME=/PATH/TO/apache_maven_3.2.3
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$PATH

$ cd Running_CLI_Using_Maven
$ mvn clean install antrun:run


[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building RunningCLI_ViaMaven 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ RunningCLI_ViaMaven ---
[INFO] Deleting /PATH/TO//Running_CLI_Using_Maven/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ RunningCLI_ViaMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ RunningCLI_ViaMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ RunningCLI_ViaMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /PATH/TO/Running_CLI_Using_Maven/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ RunningCLI_ViaMaven ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ RunningCLI_ViaMaven ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ RunningCLI_ViaMaven ---
[INFO] Building jar: /PATH/TO/Running_CLI_Using_Maven/target/RunningCLI_ViaMaven-1.0.jar
[INFO] 
[INFO] --- maven-antrun-plugin:1.7:run (default) @ RunningCLI_ViaMaven ---
[INFO] Executing tasks

main:
     [exec] {
     [exec]     "outcome" => "success",
     [exec]     "result" => {
     [exec]         "default-clustered-sfsb-cache" => undefined,
     [exec]         "default-distinct-name" => undefined,
     [exec]         "default-entity-bean-instance-pool" => undefined,
     [exec]         "default-entity-bean-optimistic-locking" => undefined,
     [exec]         "default-mdb-instance-pool" => undefined,
     [exec]         "default-missing-method-permissions-deny-access" => true,
     [exec]         "default-resource-adapter-name" => "activemq-ra",
     [exec]         "default-security-domain" => "other",
     [exec]         "default-sfsb-cache" => "simple",
     [exec]         "default-sfsb-passivation-disabled-cache" => "simple",
     [exec]         "default-singleton-bean-access-timeout" => 5000L,
     [exec]         "default-slsb-instance-pool" => "slsb-strict-max-pool",
     [exec]         "default-stateful-bean-access-timeout" => 5000L,
     [exec]         "disable-default-ejb-permissions" => true,
     [exec]         "enable-statistics" => undefined,
     [exec]         "in-vm-remote-interface-invocation-pass-by-value" => true,
     [exec]         "log-system-exceptions" => true,
     [exec]         "cache" => {
     [exec]             "simple" => undefined,
     [exec]             "distributable" => undefined
     [exec]         },
     [exec]         "cluster-passivation-store" => undefined,
     [exec]         "file-passivation-store" => undefined,
     [exec]         "mdb-delivery-group" => undefined,
     [exec]         "passivation-store" => {"infinispan" => undefined},
     [exec]         "remoting-profile" => undefined,
     [exec]         "service" => {
     [exec]             "timer-service" => undefined,
     [exec]             "remote" => undefined,
     [exec]             "async" => undefined
     [exec]         },
     [exec]         "strict-max-bean-instance-pool" => {
     [exec]             "slsb-strict-max-pool" => undefined,
     [exec]             "mdb-strict-max-pool" => undefined
     [exec]         },
     [exec]         "thread-pool" => {"default" => undefined}
     [exec]     }
     [exec] }
[INFO] Executed tasks
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ RunningCLI_ViaMaven ---
[INFO] Installing /PATH/TO/Running_CLI_Using_Maven/target/RunningCLI_ViaMaven-1.0.jar to /Users/jsensharma/.m2/repository/middleware/magic/RunningCLI_ViaMaven/1.0/RunningCLI_ViaMaven-1.0.jar
[INFO] Installing /PATH/TO/Running_CLI_Using_Maven/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/RunningCLI_ViaMaven/1.0/RunningCLI_ViaMaven-1.0.pom
[INFO] 
[INFO] --- maven-antrun-plugin:1.7:run (default-cli) @ RunningCLI_ViaMaven ---
[INFO] No ant target defined - SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.096 s
[INFO] Finished at: 2015-10-20T18:02:02+05:30
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------

NOTE: By any chance if you get the following error message while running the above project or jboss-cli.sh script then please make sure to use JDK 1.8, Because Java 7 support has been discontinued allowing for deeper integration with the Java 8 runtime.

This application requires Java specification version 1.8 or later to run 
(this Java virtual machine implements specification version 1.7)

Source Code:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WildFly/General/Running_CLI_Using_Maven

Regards
Jay SenSharma

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.