 Hello! This is Doug Tidwell coming to you from the City of the Oaks, Raleigh, North Carolina, retirement home of a surprising number of Olympic javelin throwers. This video is another in our series of features on Eclipse Chay. Today we'll show you how to create factories. One of Chay's most powerful features is its ability to build custom shared environments that make sure everyone on your team has the exact same level of tools and libraries. We'll start by creating a workspace, then we'll build a factory based on that workspace. Once the factory is created, we'll share a URL with you, the home viewer. When you visit that URL, you'll see the exact same environment we create here. You'll laugh, you'll cry, you'll call friends and loved ones to share your joy, or something like that. So let's get started. Our scenario here is that we're onboarding a new teammate, so let's create a workspace for them. Go to chay.openshift.io. If you don't have any workspaces, you'll see the new workspace page. Otherwise, click the Workspaces tab on the left and then click the Add Workspace button. Either way, you'll end up on this page. Give the workspace a name, I called mine Pet Clinic, then select the Java CentOS stack. Notice that this stack includes Tomcat and Maven. We'll use both of those as we work with the Pet Clinic app. Now click the Add or Import Project button. Select the Get tab, not the GitHub tab. Type in the URL you see on your screen and click the Add button. That's all we need to get started. Click the green Create button at the bottom of the page. Click Open in IDE in the message box that pops up. Your workspace will start shortly. As always, you'll need to log in to openshift.io if you're not already. As you can see, this workspace has imported the Pet Clinic sample app. To make life simpler going forward, click the Project menu and select Update Project Configuration. Tell Chade that this is a Maven project and click Save. Expand the project, then Source, Main, Java, the Package Name, and Model. Double-click on Pet.java to open the source code for that object. This is as good a starting point as any for someone wanting to learn the code. Later, we'll configure the factory to make sure this file is opened when the workspace starts, but we've got other work to do first. Look at the Manage Commands view. Because we told Chade this is a Maven project, it has already created a command called Build. As you would expect, it's in the Build section. It does a Maven Clean install using the current project path macro. Click the slider to tell Chade this command is applicable to the Pet Clinic project, then click Save. Now, click the green Run button to build the project. This creates the war file for the Pet Clinic app in the target directory. At this point, we could go to the terminal and copy the war file to Tomcat's web apps directory, but it would be nice to build and deploy the code with a single command. We'll create a command to do that now. Click the plus icon next to the Run tab. Double-click on Maven as the command type. Name this command Build Space and Space Run. You can actually name, spell, or capitalize this however you like, but you'll need to remember exactly what you typed later. Because we said this is a Maven command, the Clean and Install Goals are defined already. Edit the code by adding another couple of lines. After Maven builds the war file, the next step is to take that file and copy it to the Tomcat web apps directory. Type CP, then click the macros link above the text area. Double-click Current Project Path to insert that into the command. Now add slash target slash asterisk dot war space dollar Tomcat home slash web apps slash root dot war spelled and capitalized exactly as you see here. This makes the war file we just built the default application for our Tomcat server. Finally, add dollar Tomcat home slash bin slash Catalina dot sh run and the characters you see there. That will start the Tomcat server and suppress any output from the server. The last thing we want to do for this command is define a preview URL. This will be based on the randomly assigned name of the workspace as it's running in OpenShift.io. The URL gives us a link to see the Tomcat server up and running so we can make sure that our code works correctly. Clear the text that's there already, then click the macros link at the bottom of the view. Scroll down and select the server dot Tomcat 8 macro. That's all we need here because we made pet clinic the default application. You could have multiple projects and deploy them as separate web apps if you wanted but we'll keep it simple for now. Click the save button, then click the green run button. This will build and deploy the code and start Tomcat. When you get the server startup message, click the blue preview link at the top of the view. This opens the running app inside Tomcat in a new window. As you can see, everything built and deployed successfully, the web app is running on Tomcat and the world's cutest puppy and kitty are now on our screen. Chain does have a nice shortcut you can use as you're working with the code. Because the build and run command we created is in the run menu, it is associated with the run button at the top of the screen. Once you associate a command with the run button, clicking the button automatically runs the command. One click at any time and you can see the effects of any changes you've made and you don't have to go to the commands menu to do it. Before we create the factory, make a note of the complete path of the pet.java file. We'll set up the factory so that the workspace starts with that file open. It's a long file name so you'll want to paste it somewhere and retrieve it later. Now that we have our workspace configured just the way we want it, let's create the factory. Go to the workspace menu and click Create Factory. Give the factory a name, then click Create. The URL of the factory appears in the lower entry field, along with a button to copy the URL to the clipboard. Wrap up this part of the process by going to the workspace menu and clicking Stop. Go to the left-hand side of the window and click the Factories tab. Click the name of the factory you just created to edit its properties. Scroll down to the Configure Actions section. Everything you define in this section happens once the workspace is up and running. What we'll do is tell Che to run a command and open a file when the workspace loads. Next to Run Command, type the name of the command you defined. In my case, that's build and run, spelled and capitalized as you see here. Click the Add button. Now click the down arrow next to Run Command. Select Open File as the next action. Starting with the slash, paste in the complete path to the pet.java file. Click the Add button again, and you have two commands that are executed anytime someone uses the factory to open the workspace. We won't cover it in any detail here, but be aware that you can add to the workspace's commands menu. In this case, I added commands to start and stop Tomcat, and a command to run the Pet Clinic Web App in Debug Mode. All of those commands are in the workspace if you want to try them out. Now scroll to the top of the window and copy the URL of the factory. There are two versions of the URL. One will include your username, the other will not, but they both go to the same place. If you simply want to test the factory, click Open and the configured workspace will open. What I'll do instead is switch to a different browser where I will be logged in as a different OpenShift.io user. I'll paste in the URL of the factory, and in a couple of minutes I have the exact same workspace, even though I'm a completely different user. We encourage you, of course, to visit this same URL, you will get the same results. As you can see, the file pet.java is open and the code is built and deployed. When the deployment finishes, clicking the preview URL takes you to the sample application. Remember, Che is browser-based, so the factory URL works on any platform with a full-featured browser. That's a quick tour of how workspaces and factories work in Che. Factories make onboarding incredibly easy. If someone joins your team, they can use a factory to create a new workspace. And using factories eliminates the ItWorksOnMyMachine syndrome. Your machine is just like everyone else's, so it works, or doesn't, the same way everywhere. We hope this video helps you make the most of Che across your team. For the Red Hat Developer Program, this is Doug Tidwell saying may all your bugs be shallow. Cheers.