Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Deploying to Wildfly4:56 with Chris Ramacciotti
In this video we'll use the WAR we created in the last video to deploy to a running instance of Wildfly, which is a Java web application server that includes a web server.
To download Wildfly, grab the latest ".Final" version for the Java EE [version] & Web Distribution. http://wildfly.org/downloads/
Using Github With This Course
You can complete this course by using the code I've made available to you in two ways:
- Use the Github repository I've made available (recommended), or
- Use the project files linked at the bottom of this page
If you choose the recommended option of using the Github repository, it can be found at
To utilize Github with this course, you can download the Github desktop client for your system or use the command line interface provided with Git.
Clone this repository to your machine using the Github desktop client, or using the following command:
git clone email@example.com:treehouse-projects/spring-deploy-weather.git
To use WildFly and deploy the war fire we just created, you'll 0:00 wanna download the WildFly zip file and extract it to a directory of your choice. 0:03 I'm just in Downloads here. 0:07 Check the teacher's notes for a link to the download. 0:09 Assuming you've downloaded and extracted the zip file, 0:12 you'll need to set up an admin user on the command line before starting the server. 0:14 This will be the user you use to log into the web console for 0:19 web server administration, which will help us deploy our application. 0:21 So let's create that user now. 0:25 We need to run that add-user shell script located in the bin directory, so 0:28 ./bin/add-user. 0:33 Here we want to create a management user, so I'll hit enter with the default, a. 0:36 I'll use treehouse as the username. 0:39 And for the password, I'll just use a version of the word password, 0:42 except with an at sign for the a and a zero for the o. 0:47 So I'll use p@ssw0rd, and I'll re-enter that, 0:51 hopefully in the same way, p@ssw0rd. 0:56 Cool. 1:00 I'll hit Enter at this prompt, because I don't wanna add my user to any groups. 1:01 Though you may wanna use this for your own purposes. 1:06 So next, I'll enter yes, 1:10 because I want to add treehouse user to the ManagementRealm, yes. 1:12 And in the following prompt, I'll say no. 1:17 Because this is asking whether or not this application server process will be used to 1:19 connect to another app server process. 1:23 So how about no. 1:25 Cool, we're done. 1:28 Now, to start the WildFly server, we'll use the standalone script, 1:30 ./bin/standalone. 1:34 Now you'll see a bunch of output here, and after it's done booting, 1:40 you can switch to a browser and check out the management console at localhost, 1:45 and then we'll go, 9990. 1:51 And here is the management interface for the WildFly web server, cool. 1:53 Now, there are two high-level tasks we'll need to work through to get 1:58 a running application. 2:01 First, we'll set up our datasource, and second, we'll upload the war file. 2:02 So let's tackle those one at a time, starting with the datasource. 2:07 In your WildFly dashboard, next to where it says Create a Datasource, 2:10 let's click the Start link. 2:15 And on this page, you'll choose Subsystems > Datasources > and 2:16 Non-XA, since our transaction management spans only a single database. 2:21 So with this option selected, I'll click Add. 2:27 Now, we're gonna create an in-memory H2 database which is 2:30 available to us through WildFly out of the box. 2:33 If you want to configure another database provider such as MySQL, 2:35 you'll need to have that server installed and 2:38 running somewhere that's accessible from wherever WildFly is running. 2:40 So in this prompt, I'll choose H2 Datasource, and click Next. 2:44 Here for the name, I'll just use weather. 2:49 And for the JNDI name, I'll use the same name that we used in 2:52 application.properties, and I'll use java:/weather. 2:56 Okay, in the next prompt, all the proper defaults should be selected for you, so 3:01 we can click through this. 3:05 And if you wanted to change these default configuration settings, 3:08 you certainly could. 3:10 One thing to keep an eye on here is this option here at the end of 3:12 the connection URL, this DB_CLOSE_DELAY=-1. 3:17 Now, this makes sure that the in-memory database isn't closed when the last 3:21 connection to it is closed. 3:25 Now, if we delete this, 3:26 we'll lose our data every time there are no active connections. 3:27 So I'll leave it there. 3:31 Okay, let's click Next. 3:33 And on this screen, you can go ahead and click Test. 3:36 And looks like I was able to successfully create a connection to the database. 3:40 Cool. 3:45 So I will click on Finish. 3:46 Just like that, our data source is configured. 3:50 You should be prompted to reload your server, so I'll do that now. 3:52 So now, when our deployed application looks up the datasource using JNDI, 3:57 it'll find it. 4:01 Hey, speaking of that deployed application, shall we deploy? 4:02 At the top of the management console, you should see a tab called Deployments. 4:07 Go ahead and click that. 4:11 And then you should click on, yep, you guessed, it, the Add button. 4:12 Okay, indeed, we would love to upload a new deployment. 4:16 Let's click Next. 4:20 And let's choose that war file we created in the last video. 4:21 So I'll choose that war file. 4:24 Click Open. 4:26 And then on the next prompt, I can accept all the defaults. 4:28 And after clicking Finish here, WildFly will hook into my app's Java code, 4:31 kicking off all that Spring Boot magic. 4:35 In fact, if you were to check out your terminal, 4:37 you'd see a lot of that Spring Boot output that you have become familiar with. 4:40 Now, after the application is done deploying, 4:45 open a new tab and go to localhost:8080, and there is our running web app. 4:48 We've successfully deployed a war to a running web server. 4:53
You need to sign up for Treehouse in order to download course files.Sign up