Deploying to Tomcat

In this training, we look at deploying Stack 3 projects to Tomcat servers. We'll discuss the deploy project that is in every Stack 3 project, the Tomcat Encryption Tool, and Tcat.

Slides for this presentation can be found here: Media:TomcatPresentation.pptx‎

Presentation, Part 1

Get Adobe Flash player

Lab #1

In this lab we'll create a Stack 3 project, configure a local tomcat instance, and create a JNDI property.

1. Start by opening the Stack Starter and creating a new project.

  1. On the first screen, you can give it a name and package of your choosing. Save it in a directory without spaces and keep this directory in mind for future steps.
  2. On the second screen, we'll change a few options to make the project simpler:
    1. Under 'Security', uncheck 'Use LDS Account Authentication'
    2. Under 'Service Layer', uncheck 'Use a database?'
  3. On the last screen, click 'Build'. Once it is complete, you can close the Stack Starter.

2. Import the project into an IDE of your choosing. In Eclipse, you do this by right-clicking in the Project Explorer, selecting Import ..., then choosing Maven > Existing Maven Projects, and finally choosing the root of your project.

3. Configure your Tomcat server to use your new project's configuration.

  1. For those using the LDSTech IDE, you can do this by simply adding the project to an existing LDSTech Server (Right-click on the web project and select Run As... > Run on Server, then choose the LDSTech server that has been created for you).
  2. Those using IntelliJ should follow this guide .

4. You should now be able to view the project at: http://localhost: 8080/<project name> (http://localhost: 8080/stack-starter) if you kept the defaults, or if you are using the LDSTech IDE, you can open up the property page for the server by double-clicking on the server; you can then click the link on the property page under 'Deployed Applications' to take you to your application in your default browser.)

5. Add a JNDI property to

6. Add an entry in server.xml, inside the GlobalNamingResources tags:

<Environment name="someProperty" type="java.lang.String" value="${}" />

7. Add a mapping to context.xml (in the web project, under src/main/webapp/META-INF/):

<ResourceLink name="appProperty" global="someProperty" />

8. Consume it in Spring by adding the following to your applicationContext.xml (in the web project, under src/main/resources/META-INF/spring):

<jee:jndi-lookup id="jndiProperty" jndi-name="appProperty" />

9. Make a simple Spring MVC controller named that will help display JNDI values:


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

public class PropertyController {
	private String jndiProperty;

	public String viewProperties(ModelMap modelMap) {
		modelMap.addAttribute("jndiProperty", jndiProperty);
		return "index";

10. Update index.jsp (in src/main/webapp/WEB-INF/views) to display the variable:

		<p>JNDI Property: ${jndiProperty}</p>

11. Restart your web application and reload the home page - you should see your JNDI value.

12. In your deploy project, create a and copy the contents from into it.

13. Change your to equal something other than 'foo'.

14. Change to the stage environment.

  1. In the LDSTech IDE, this is done by double-clicking on the server, unchecking 'Use maven property as default', then using the drop-down to select stage. Save the server and restart it.
  2. In IntelliJ, follow the steps above, but specify stage instead of dev (add a parameter to the config build called 'tomcatEnv'). Restart the server.

15. You should see your new value when you reload the home page.

Lab 1 Solution

Get Adobe Flash player

Presentation, Part 2

Get Adobe Flash player

Lab #2

In this lab, we'll encrypt a JNDI property and configure Tomcat to decrypt it properly.

1. Note the key when your server first starts up. It'll look something like this (NOTE: Don't actually use this key, as it won't work for you!):

====================Tomcat Public Key Begin==================
=====================Tomcat Public Key End===================

2. Download the Tomcat Encryption Tool. Launch it by either double-clicking on the jar, or by running it from the command-line:

$ java -jar TomcatEncryptTool.jar

3. Paste the key you found in your Tomcat output in the 'Key' field, then add a value to encrypt under 'Value'.

4. Copy the output to your (If you did the previous lab, your environment might still be set to 'stage', so either change it back to dev or make sure you add the encrypted property to stage). It should look something like this:{encrypted}I6g0bDoQog2oV8DJncSpCDdO8+j0qc3e6ABgD0oZgGxAORW0RBv1q68ULqk5AhFxErXWybdWX7SxuEMGdMPWnmOhzB3KGE8dSH/SfB7OyR0Ul2ClVFaJYGXw3gIfBl+LfPYp7tQWLR0GbdQogSABrTmAJU+9

5. The Stack Tomcat module is already in your deploy project's POM by default, so we won't need to add that here.

6. Your server.xml (in your deploy project) is also already configured out of the box, but you may want to go look at it anyway to see what the configuration looks like.

7. Restart your server and reload the page - you should see the value you encrypted.

Lab 2 Solution

Get Adobe Flash player

Presentation, Part 3

Get Adobe Flash player

Lab #3 (there is no video for this lab)

This is a simple lab designed to help familiarize you with the Tcat console. This lab is not available unless you are in the live training.

1. Login to the console running on my machine at the URL given out in training.

2. Login with the username 'training' and password 'training'.

3. Click on the 'Servers' tab to see all servers registered with this console. The one with a green indicator next to it (that isn't named 'Tcat Server') is the node that is running. Click on it.

4. Click on the 'Logs' sub tab, then find that catalina.* log file. Click the download link on the top-right to download it.

5. Click on the 'Files' sub tab, then the 'conf' directory. You'll see all of the files we discussed in the first part of this training.

6. View the '' file. It should look a lot like the files we modified earlier.

Presentation, Part 4

Get Adobe Flash player

Files used

Media:TomcatPart1.swf Media:TomcatLab1.swf Media:TomcatPart2.swf Media:TomcatLab2.swf Media:TomcatPart3.swf Media:TomcatPart4.swf

This page was last modified on 15 September 2016, at 15:07.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.