Table of Contents

  1. Revision History
  2. Motivation
  3. Special Note: Transactions
  4. Walkthrough
    1. Java
    2. Tomcat
    3. JPetStore - Download
    4. MySQL
    5. MySQL JDBC Driver
    6. JPetStore - Database
    7. JPetStore - Deploy
    8. JPetStore - Driver Setup
  5. Troubleshooting
    1. No action instance for path /shop/index could be created
    2. Error getting transaction
    3. Can't get Transactions to work on Red Hat 9.0! / Edited my.cnf - Now Mysql doesn't start!
  6. Comments
    1. My personal site / Tutorial Requests - by Adrian Lanning
    2. Linux - Transactions / INNODB / my.cnf - by Adrian Lanning
    3. Transactions / INNODB / my.cnf - by Chris Smith
    4. Create User / GRANT usage - by Chris Smith
    5. Access Denied / GRANT usage - by Marc Mulzer
    6. Linux Install - by George Entenman
    7. Solaris Install - by Christoph Kutzinski

Revision History

Version 2.2.2 - 02/13/04 Version 2.2.1 - 01/27/04 Version 2.2 - 01/22/04 Version 2.1 - 01/11/04 Version 2 - 12/30/03 Version 1 - 10/13/03

Motivation

I made this walkthrough in the hopes of saving someone some time when installing Clinton Begin's excellent JPetStore application.

This guide will walk you through the steps involved in setting up a Windows system to run JPetstore. It does not assume any prior installation/configuration of dependent software.

Linux / Solaris 9 Note:

The steps in this walkthrough are generally the same for a Linux or Solaris 9 installation.

George let me know how he got JPetStore to work on Linux and Christoph let me know how for Solaris 9.

Maria Tzvetanova pointed out that the lowercase table names in the mysql setup scripts In Version 1 caused errors when used on Linux systems. This is because (unlike Windows) MySQL on Linux is case-sensitive. She has supplied updated mysql scripts with uppercase table names which are included in Version 2.

Special Note: Transactions

The MySQL scripts that come with this walkthrough set up tables of the default (ISAM) type. These tables do NOT support transactions but are very fast. The MySQL driver is smart enough to act as if transactions occur so that transaction-aware software (like JPetStore) will still run fine. But in reality, each SQL command is a seperate "transaction".

If you need transaction support, use the MySQL script that comes with the JPetStore distribution (in the ddl/mysql directory). That file uses INNODB tables which do support transactions.

You will still need to set up a user so you can still use the jpetstore-mysql-create-user.sql script.

Note: Check out Chris Smith's helpful comment regarding the use of INNODB tables.

Chris sent me a modified version of the INNODB schema script that comes with JPetStore which supports re-running the script to reset the database to the starting state. See the above comment.

Walkthrough

  1. Java
    1. Download Java SDK 1.4.2_01 (had trouble using the NetBeans bundle so I recommend using the regular SDK package).

  2. Tomcat
    1. Download and install the latest version of Tomcat from http://jakarta.apache.org/site/binindex.cgi.
      1. I install all my Apache apps to "c:\program files\apache" to keep it simple.
      2. Just keep all the other defaults the same, and input your preferred admin password when prompted.
    2. Start Tomcat. You can use either the Windows Service or the Start Menu shortcut, "Start->Programs->Apache Tomcat 5.0->Start Tomcat".
    3. Verify that Tomcat is working correctly.
    4. Goto http://localhost:8080. If you see a Tomcat base page you're good.
    5. Goto http://localhost:8080/jsp-examples and try out a couple of the examples to confirm that Tomcat is working properly.

      Note: I had trouble getting the example, http://localhost:8080/jsp-examples/jsp2/misc/config.jsp to work. To fix this exception I followed the on-screen instructions and copied "$JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart." :)

  3. JPetStore - Download
    1. Download and unzip the latest version of JPetStore to a temp directory.

  4. MySQL
    1. Download MySQL 4.0.14b, unzip, and run Setup.
    2. Goto your default MySQL directory (C:\mysql for me) and copy my-medium.cnf to my.cnf. Now move my.cnf to C:\.
    3. Open a command prompt (Dos prompt). Now goto, "C:\mysql\bin" and run, "mysqld-nt -install". This will install the MySQL daemon (server) as a Windows Service that will start automatically when Windows starts. You can verify this by going to Start->Control Panel->Administrative Tools->Services under Win2000.
    4. Start the MySQL Service.
      Win2000:
      Go to Start->Control Panel->Administrative Tools->Services.
      Double-click the MySQL service
      click the Start button.
    5. Set Root MySQL password.     *** Very Important Step ***
      1. Goto "C:\mysql\bin".
      2. Run "mysqladmin -uroot password NEW-PASS" where NEW-PASS is your password of choice.

        Note:Don't type the quotes...


    6. Verify MySQL is running correctly.
      1. Run "mysql -uroot -p". You will be prompted for a password. Just enter in whatever you typed for NEW-PASS.
      2. You should see a "mysql>" prompt. If not, check Google for whatever error code you received.
      3. Run "show databases;".

        Note: Don't forget the ';'. If you ever see a prompt with just a " ->" then you know you forgot the ';'.


      4. If you don't see,
        +----------+
        | Database |
        +----------+
        | mysql    |
        | test     |
        +----------+
        2 rows in set (0.02 sec)
        	
        then you know something is wrong...try Google.

  5. MySQL JDBC Driver
    1. Download the MySQL JDBC Driver, mysql-connector-java-3.0.9-stable.
    2. Unzip the driver. Copy the file, "mysql-connector-java-3.0.9-stable-bin.jar" to Tomcat's common/lib directory.

  6. JPetStore - Database
    1. Now download these files to your computer:
      jpetstore-mysql-schema.sql
            or jpetstore-mysql-schema-innodb.sql if you want transaction support (see Chris's comment).
      jpetstore-mysql-dataload.sql
      jpetstore-mysql-create-user.sql
    2. Make sure you logged out of mysql, jump back to your shell prompt, and execute the following commands.
      1. "mysql -uroot -p < jpetstore-mysql-schema.sql"   OR  "mysql -uroot -p < jpetstore-mysql-schema-innodb.sql" for transaction support.
      2. "mysql -uroot -p < jpetstore-mysql-dataload.sql"
      3. "mysql -uroot -p < jpetstore-mysql-create-user.sql"
      Note: If you get an error like this: "mysql: command not found" that means you don't have the mysql program in your path. Just copy the '*.sql' files to your mysql/bin folder and run the commands from there.
    3. If you don't see any errors, it worked correctly.

  7. JPetStore - Deploy
    1. Find jpetstore.war in the build/wars folder of wherever you unzipped the JPetStore download to.
    2. Copy jpetstore.war to your Tomcat/webapps folder. For me this was at "C:\Program Files\Apache\Tomcat 5.0\webapps". Tomcat will automatically deploy your app if you have it started. If it's not started just follow the instructions in step 2.
    3. Don't try to access (run) the app yet.

  8. JPetStore - Driver Setup
    1. Find /webapps/jpetstore/WEB-INF/classes/properties/petstore.properties from your Tomcat directory. (c:\program files\apache\tomcat 5.0, for me)
    2. Change the default (oracle) values to match the following:
      SimpleDriver=org.gjt.mm.mysql.Driver
      SimpleUrl=jdbc:mysql://localhost:3306/jpetstore
      SimpleUsername=jpetstore
      SimplePassword=ibatis9977
      	
    3. Save it!

  9. Test
    1. Shutdown and restart your Tomcat Web Server by either stopping the Service or using the System Tray icon.
    2. Once Tomcat has restarted, click here (link will open a new window): http://localhost:8080/jpetstore .
    3. Have fun!

Troubleshooting

I figured I'd try to do things wrong and see what errors I got in case it happens to one of you. :)


Comments

One of the best parts about sharing online is getting great feedback. I've included what I felt to be the most useful / most frequently asked comments from the community.