How to deploy and undeploy with the JBoss CLI in Standalone mode
While standalone EAP/Wildfly instance is running and the CLI is connected to its controller, e.g.
Connected to standalone controller at localhost:9999
[standalone@localhost:9999 /]
Now to deploy an application, all that's necessary is to type in deploy and the path to the package (the tab-completion will help to navigate the filesystem), e.g.
[standalone@localhost:9990 /] deploy /tmp/jboss-helloworld-singleton.war
16:34:58,778 INFO [org.jboss.as.repository] (management-handler-thread - 11) JBAS014900: Content added at location /opt/wildfly-8.1.0.Final/standalone/data/content/9a/915b50734baf4b9fa8b359aa5e8547f1218390/content
16:34:58,784 INFO [org.jboss.as.server.deployment] (MSC service thread 1-25) JBAS015876: Starting deployment of "jboss-helloworld-singleton.war" (runtime-name: "jboss-helloworld-singleton.war")
16:34:58,834 INFO [org.jboss.weld.deployer] (MSC service thread 1-32) JBAS016002: Processing weld deployment jboss-helloworld-singleton.war
16:34:58,841 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-32) JNDI bindings for session bean named Counter in deployment unit deployment "jboss-helloworld-singleton.war" are as follows:
java:global/jboss-helloworld-singleton/Counter!org.jboss.as.quickstarts.singleton.Counter
java:app/jboss-helloworld-singleton/Counter!org.jboss.as.quickstarts.singleton.Counter
java:module/Counter!org.jboss.as.quickstarts.singleton.Counter
java:global/jboss-helloworld-singleton/Counter
java:app/jboss-helloworld-singleton/Counter
java:module/Counter
16:34:58,871 INFO [org.jboss.weld.deployer] (MSC service thread 1-21) JBAS016005: Starting Services for CDI deployment: jboss-helloworld-singleton.war
16:34:58,882 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016008: Starting weld service for deployment jboss-helloworld-singleton.war
16:34:59,306 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-1) Initializing Mojarra 2.2.6-jbossorg-4 20140501-1134 for context '/jboss-helloworld-singleton'
16:34:59,491 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017534: Registered web context: /jboss-helloworld-singleton
16:34:59,506 INFO [org.jboss.as.server] (management-handler-thread - 11) JBAS018559: Deployed "jboss-helloworld-singleton.war" (runtime-name : "jboss-helloworld-singleton.war")
[standalone@localhost:9990 /]
You can make sure that the application is deployed by checking deployments in the standalone.xml
<deployments>
<deployment name="jboss-helloworld-singleton.war" runtime-name="jboss-helloworld-singleton.war">
<content sha1="9a915b50734baf4b9fa8b359aa5e8547f1218390"/>
</deployment>
</deployments>
<deployment name="jboss-helloworld-singleton.war" runtime-name="jboss-helloworld-singleton.war">
<content sha1="9a915b50734baf4b9fa8b359aa5e8547f1218390"/>
</deployment>
</deployments>
To undeploy this application its name has to be passed in as the argument to undeploy (if you type in undeploy, the tab-completion will list all the deployed applications and help complete the deployment name), e.g.
[standalone@localhost:9990 /] undeploy jboss-helloworld-singleton.war
Now if you check the standalone.xml you'll see that the deployment is gone from the list.
Based on this simple example you can see that the deploy command actually automatically performs two steps: uploads the content and enables it. And the undeploy command, by default, disables the application and removes its content from the repository.
If necessary though, you can just upload the content to the repository without enabling it. The deploy command has --disabled switch for that, e.g.
[standalone@localhost:9990 /] deploy /tmp/jboss-helloworld-singleton.war --disabled
16:36:51,912 INFO [org.jboss.as.repository] (management-handler-thread - 14) JBAS014900: Content added at location /opt/wildfly-8.1.0.Final/standalone/data/content/9a/915b50734baf4b9fa8b359aa5e8547f1218390/content
[standalone@localhost:9990 /]
Which will result in the following in the standalone.xml
<deployments>
<deployment name="jboss-helloworld-singleton.war" runtime-name="jboss-helloworld-singleton.war" enabled="false">
<content sha1="9a915b50734baf4b9fa8b359aa5e8547f1218390"/>
</deployment>
</deployments>
<deployment name="jboss-helloworld-singleton.war" runtime-name="jboss-helloworld-singleton.war" enabled="false">
<content sha1="9a915b50734baf4b9fa8b359aa5e8547f1218390"/>
</deployment>
</deployments>
Then to enable the deployment you'll need to specify just its name as the argument (if you press the tab key after '--name=' it'll help you autocomplete the value)
[standalone@localhost:9990 /] deploy --name=jboss-helloworld-singleton.war
16:45:01,673 INFO [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015876: Starting deployment of "jboss-helloworld-singleton.war" (runtime-name: "jboss-helloworld-singleton.war") 16:45:01,719 INFO [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016002: Processing weld deployment jboss-helloworld-singleton.war 16:45:01,724 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-14) JNDI bindings for session bean named Counter in deployment unit deployment "jboss-helloworld-singleton.war" are as follows: java:global/jboss-helloworld-singleton/Counter!org.jboss.as.quickstarts.singleton.Counter java:app/jboss-helloworld-singleton/Counter!org.jboss.as.quickstarts.singleton.Counter java:module/Counter!org.jboss.as.quickstarts.singleton.Counter java:global/jboss-helloworld-singleton/Counter java:app/jboss-helloworld-singleton/Counter java:module/Counter 16:45:01,754 INFO [org.jboss.weld.deployer] (MSC service thread 1-11) JBAS016005: Starting Services for CDI deployment: jboss-helloworld-singleton.war 16:45:01,766 INFO [org.jboss.weld.deployer] (MSC service thread 1-18) JBAS016008: Starting weld service for deployment jboss-helloworld-singleton.war 16:45:02,115 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-15) Initializing Mojarra 2.2.6-jbossorg-4 20140501-1134 for context '/jboss-helloworld-singleton' 16:45:02,219 INFO [org.wildfly.extension.undertow] (MSC service thread 1-15) JBAS017534: Registered web context: /jboss-helloworld-singleton 16:45:02,237 INFO [org.jboss.as.server] (management-handler-thread - 20) JBAS018559: Deployed "jboss-helloworld-singleton.war" (runtime-name : "jboss-helloworld-singleton.war")
[standalone@localhost:9990 /]
And then in standalone.xml, the enabled="false" disappears.
Now, when undeploying, If you don't want to remove the content but just disable (stop) the running application then you can use --keep-content switch, e.g.
[standalone@localhost:9990 /] undeploy jboss-helloworld-singleton.war --keep-content
16:47:37,137 INFO [org.wildfly.extension.undertow] (MSC service thread 1-19) JBAS017535: Unregistered web context: /jboss-helloworld-singleton
16:47:37,153 INFO [org.jboss.weld.deployer] (MSC service thread 1-27) JBAS016009: Stopping weld service for deployment jboss-helloworld-singleton.war
16:47:37,180 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015877: Stopped deployment jboss-helloworld-singleton.war (runtime-name: jboss-helloworld-singleton.war) in 45ms
16:47:37,197 INFO [org.jboss.as.server] (management-handler-thread - 23) JBAS018558: Undeployed "jboss-helloworld-singleton.war" (runtime-name: "jboss-helloworld-singleton.war")
[standalone@localhost:9990 /]
If you press the tab key after the deployment name, it'll autocomplete the --keep-content argument. And if you now look into the standalone.xml, you'll see enabled="false" again.
If you want to re-deploy an already deployed application (whether enabled or disabled) and replace its content with the new version, the deploy command will fail unless you specify --force argument.
Comments
Post a Comment