官术网_书友最值得收藏!

Managing applications using the deployments folder

After configuring and customizing the WildFly standalone, it's time to deploy our first application. WildFly provides a lot of methods to deploy applications, one of them being via the deployment scanner (well known to those of you who come from the JBoss AS version). Basically, all you need to do is to copy your artifact into the deployments folder of your standalone instance.

In a production environment, you had better turn off the deployment scanner to avoid replacing a deployment accidentally—you would be in very big trouble. Do use the proper "deploy" operation using either the CLI or the Admin Console. We will see both in this chapter.

Getting ready

In this recipe, we will need a Java web application. If you want, you can use one of my projects from my GitHub account, at the following address: https://github.com/foogaro/wildfly-cookbook.git.

You can git-clone the repository or just download it as a ZIP archive. Either way, create a folder named github into the WFC folder, and place the source into it.

Using the git-clone command, do as follows:

$ cd ~/WFC
$ mkdir github
$ cd github
$ git clone https://github.com/foogaro/wildfly-cookbook.git

Once git has done with cloning the repo, you can find a project called example. To compile the project, do as follows:

$ cd ~/WFC/github/wildfly-cookbook/example
$ mvn -e clean package

The preceding commands compile the project and generate the web application artifact into a folder named target. There you can find the application example.awar, ready to be deployed.

Note

There is also the official WildFly quickstarts repository, which has plenty of precious resources to look at, and it is also available for contribution at the following address: https://github.com/wildfly/quickstart.

Now, assume that we are going to use the default standalone folder as the base configuration path of our instance. To see everything in action, it's better to first run WildFly and then start managing the application itself using the deployments folder.

How to do it…

  1. First, let's start up WildFly:
    $ cd $WILDFLY_HOME
    $ ./bin/standalone.sh
    ...
    WFLYSRV0025: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) started in 3087ms - Started 202 of 379 services (210 services are lazy, passive or on-demand)
  2. Now keeping your terminal windows visible, open your favorite file manager tool, and copy example.war into the deployments folder.

    Alternatively, you can copy the web application using a new terminal, using the following command:

    $ cp ~/WFC/github/wildfly-cookbook/example/target/example.war $WILDFLY_HOME/standalone/deployments
  3. A few seconds later (the timer interval is set for every 5 seconds, so you may wait a few milliseconds or 5 seconds), we'll get the following output:
    22:51:31,396 INFO  [org.jboss.as.repository] (DeploymentScanner-threads - 1) WFLYDR0001: Content added at location /home/luigi/WFC/wildfly/standalone/data/content/21/7dd6250d5bc4afcabdffb0b25c99db92239b5a/content
    22:51:31,447 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "example.war" (runtime-name: "example.war")
    22:51:31,986 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0021: Registered web context: /example
    22:51:32,046 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "example.war" (runtime-name : "example.war")

    And you should also get a new file in the deployments folder named example.war.deployed. This is a marker saying that the application has been successfully deployed. In case of an error, any operation would have been rolled back and a new file named example.war.failed would have been created.

  4. Now, can you guess how to undeploy it? Yes... rename the marker file extension with .undeploy as follows:
    22:55:17,702 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0022: Unregistered web context: /example
    22:55:17,736 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-4) HV000001: Hibernate Validator 5.1.3.Final
    22:55:17,801 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment example.war (runtime-name: example.war) in 109ms
    22:55:17,817 INFO  [org.jboss.as.repository] (DeploymentScanner-threads - 1) WFLYDR0002: Content removed from location /home/luigi/WFC/wildfly/standalone/data/content/21/7dd6250d5bc4afcabdffb0b25c99db92239b5a/content
    22:55:17,817 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0009: Undeployed "example.war" (runtime-name: "example.war")

    And in the deployments folder, a new file named example.war.undeployed has been created. How do we redeploy it now? Delete the two marker files, or create a new one named example.war.dodeploy.

How it works…

To recap what we've learned so far, marker files always have the same name as the application plus the suffix. The following table summarizes all the available markers:

主站蜘蛛池模板: 奈曼旗| 莱芜市| 昌江| 天峨县| 桂林市| 保靖县| 秦皇岛市| 贵南县| 马龙县| 巴中市| 闸北区| 武清区| 诸城市| 卢龙县| 和静县| 蕲春县| 依兰县| 大姚县| 玉屏| 军事| 西和县| 瑞安市| 揭西县| 文山县| 饶河县| 凤台县| 简阳市| 永丰县| 荥经县| 商丘市| 从江县| 东乌珠穆沁旗| 嵊州市| 建平县| 无锡市| 涞水县| 镶黄旗| 应用必备| 剑阁县| 信宜市| 南澳县|