 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.openchef.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 get hub 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 openchef.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 shade 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 shade 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 shade 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 an 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 dot 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 workspaces 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 it works on my machine 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.