Travel Log - Sample Java Web Application

Sample Code & Libraries>Travel Log Sample Java Web Application
Community Contributed Software

  • Amazon Web Services provides links to these packages as a convenience for our customers, but software not authored by an "@AWS" account has not been reviewed or screened by AWS.
  • Please review this software to ensure it meets your needs before using it.

Travel Log is a code sample that demonstrates how to use Amazon Web Services in a Java Web application. It uses Amazon S3 to store trip photos and a Java Persistence API to store journal entries and photo metadata in Amazon SimpleDB.


Submitted By: Wade@AWS
AWS Products Used: Amazon SimpleDB
Language(s): Java
License: Apache 2.0
Created On: December 16, 2010 6:48 PM GMT
Last Updated: November 8, 2013 4:19 PM GMT

About This Sample

Store Metadata in SimpleDB
Store journal entries and photo metadata in Amazon SimpleDB using a JPA interface.

Upload Images to Amazon S3
Upload photos from your computer to Amazon S3 so they are durably stored.

Get E-mail Notifications from Amazon SNS
Get notified automatically by e-mail when new comments are added.

What's New?

  • 2011-06-15: Sample code for dynamically naming AWS resources based on a system property. See "Dynamically Naming AWS Resources" below.


Before you can use the Travel Log, you will need the following:

Running the Sample

Configuring the Source

After you've downloaded the source and before you compile the application, update the file to include the access and secret key information you received earlier when you signed up for your AWS account.

Your version of the file should look like this:

# You must configure the accessKey, secretKey
# running the Travel Log application

When you are finished editing the file, save it. You should now be ready to build the Web archive (WAR) file and try out the Travel Log application in your browser.

Building the Source

With the application source code downloaded, you use Apache Maven to build the code. Open a terminal, use cd to enter the directory, and then type:

$ mvn compile war:war  

The build process downloads all the dependencies that the application uses, compiles all the code, and builds the WAR file. The WAR file, called TravelLog-1.0.0.war, resides in the target directory of the project.

One dependency that Maven automatically downloads is the SimpleJPA library, which is listed in the pom.xml file. Because Maven handles the dependency for you, you don't have to download the library yourself.

When the build is complete, you will see a message like this:

[INFO] Building war: /home/user1/Projects/travellog/target/TravelLog-1.0.0.war
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15 seconds
[INFO] Finished at: Sat Nov 20 18:57:15 CST 2010
[INFO] Final Memory: 19M/118M
[INFO] ------------------------------------------------------------------------

Deploy this WAR file to the Tomcat server by copying the file to the webapps folder in Tomcat's home, like this:

$ cp TravelLog-1.0.0.war ${TOMCAT_HOME}/webapps  

If you already have Tomcat started when you copy the WAR file, Tomcat picks up the change automatically and deploys the WAR file. If you see the WAR file unpacked in the webapps folder (it will be in the TravelLog-1.0.0 folder), Tomcat has found the WAR and deployed it. You can be certain that the WAR has started successfully be viewing the localhost.log file in your Tomcat's log folder. The log file will contain an entry that looks like this if the Web application has been deployed correctly:

INFO: Set web app root system property: 'webapp.root' = [/home/ngood/local/tomcat/webapps/TravelLog-1.0.0/]
Nov 18, 2010 8:06:41 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()

Viewing the Application in Action

Open the Travel Log application by going to the Tomcat URL of the Web application. Because port 8080 is the default port for Tomcat, on your machine that URL is probably http://localhost:8080/TravelLog-1.0.0/. The server name may differ if you've deployed the application to a different server.

If for some reason the server URL does not work but you know that Tomcat is running, check the logs again to make sure nothing is wrong with the configuration. If you've specified incorrect keys for the access keys or if the bucket name is formatted incorrectly, the application will fail to start, and you should see the error message in the logs.

When you run the application for the first time, it prompts you to set up a user name and password. These are stored in the database, so when you start the application the next time, you won't have to register as a new user.

Dynamically Naming AWS Resources

You may want to run multiple instances of an application to separate personal, test, and production environments. AWS Elastic Beanstalk provides a way to easily run multiple environments using the same application source, but your application needs to easily point to different AWS resources consumed by each environment (Amazon S3 buckets, Amazon SimpleDB domains, etc.).

The Travel Log demonstrates one technique to achieve this resource separation using system properties. If you set the system property application.stage, Travel Log will automatically append the stage name to any AWS resources created and consumed. For example, if you pass the following argument to your Tomcat JVM, the Travel Log will use a bucket named travellog-photo-prod to store data in Amazon S3:


Alternately, using this command, the Travel Log will store and retrieve photos from "travellog-photo-beta":



©2017, Amazon Web Services, Inc. or its affiliates. All rights reserved.