Setting Up the Development Environment

Phase 0


Context

Our MIS division has identified the applications needed to develop, test and deploy FabFlixs so that it is consistent with our Linux production environment. Fortunately, all are freely available and have proven their stability and robustness.

Since our development PCs run Windows, we need to install an environment to simulate a Linux interface. Cygwin has been chosen for this purpose, as it can support the other applications needed for this project.

PostgreSQL has been chosen as the database. There are both Windows and Linux versions of PostgreSQL; we use the latter running under cygwin so that we are sure it will work in our production environment.

To develop Web software, we need the Java development environment; the most current version, 6.0, is required. In addition the Java language itself, we need the JDBC libraries so that the developed Java code can interface with PostgreSQL. Further, we need to install C/C++ to allow us the capability to enhance the SQL available in PostgreSQL (write stored procedures in C). Fortunately, gnu C/C++ is available as part of cygwin.

We also install Tomcat, a service that handles dynamic web content and servlets–features we will be using in developing FabFlixs.

Management has okayed using Windows for developing any aspect of FabFlixs that can be ported to Linux without change; for example, text editing and Java programming development can be done in Windows, as .txt, .java and .class files are portable between the two environments. However, for system dependent aspects of FabFlixs, development must be done under cygwin to ensure compatibility with our production system. We recommend using the Windows environment as much as feasible, as it has a richer tool set than cygwin; that will perhaps speed up development.

In developing FabFlixs, you may use any software tools to which you have legitimate access. In particular, consider using an integrated development environment (such as Eclipse or Netbeans).


Notes

If you have a non-Windows machine (e.g., a Mac or a computer running Linux or some flavor of Unix) you want to use for development, that's fine–but your installation procedures will be different than those given here. Limits on course resources prevent us from supporting multiple environments. We'll help you as we can with installs on non-Windows platforms, but we cannot be responsible for any substantial research or debugging that may be required to get such a system to work correctly.

These installations do not all need to be done in one sitting; a convenient place to break is when a package's installation is complete. (Testing of that installation can be done at a later time.) We recommend you install the packages in the order given, as some later ones require the presence of earlier ones (.e.g., Java 6.0 needs to be installed for Tomcat to be installed).


What to Turn In

Nothing; the point of this phase is to set up tools so you are ready to undertake the FabFlixs phases that follow.


Installing Java

You will need Java on your machine; we strongly recommend getting the latest version, Java 6.0 (also known as Java 1.6.0) update 1. If you do not already have it installed on your machine, or you want to update from an older version:

  1. Go to http://java.sun.com/javase/downloads/index.jsp.

  2. Choose either the JDK itself or JDK with the NetBeans development environment (don't choose the JRE--that does not have the compiler).

  3. Choose a Windows installation. (It's typically easiest and faster to choose the Online installation.)

  4. Accept the license.

  5. Save the installation file to disk.

  6. Launch the setup file you just downloaded.

  7. Accept the license; click Next.

  8. If you do not have this version of Java already on your machine, you will be asked in which directory to install it; it's best to accept the default. (Some folks have had big hassles getting environment settings (see below) to work correctly when the folder is changed.)

  9. Accept the default setups for the various components presented to you (these will differ depending on whether you downloading just the JDK or both the JDK and NetBeans); click Next at each stage to install that component. It can take some time for installation of a component to complete..

  10. Click Finish.

  11. Right-click on My Computer; choose Properties. Click the Advanced tab. Click Environment Variables. Under System Variables, find the PATH variable and Edit it; add this to the end of the Variable Value:

    ;C:\jdk1.6.0_01\bin

    Then find the CLASSPATH variable. If it doesn't exist (if you've never used your system to develop Java code, it probably won't, ), click the New... button. For Variable Name enter CLASSPATH; for Variable Value enter

    .;C:\jdk1.6.0_01\lib.

    or add that string onto the end of the existing CLASSPATH. (If you have installed a previous version of Java, instead of adding these references to the paths, change the exiting ones for the java BIN and LIB files to refer to the folder that contains the just-downloaded version of java -- it will be likely be \jdk.1.6.0_01.)

  12. Click OK; click OK again; click OK again!

Java should now be ready to use. To check that the CLASSPATH and PATH variables are properly set, open a command window and enter javac -version. If the version prints (along with a bunch of help text), the PATH is working; if you get the message 'javac' is not recognized as an internal or external command, operable program or batch file, either the PATH is incorrect, or you did not start with a fresh command line window after you changed the PATH command. When trying to run a java program, if you get a ClassNotFoundException exception, check the CLASSPATH variable.

Once you are sure Java is working, you can (but do have have to) delete any old versions of Java from your machine.


Installing cygwin and related tools

  1. Go to http://www.cygwin.com; familiarize yourself with cygwin's purpose and structure (e.g. click on the links in the gray box on the left of the screen). We need the cygwin basic environment, as well as the postgreSQL, zip and gnu C/C++ modules that can be incorporated into a cygwin installation.

  2. Click on Install or update now!; save the setup.exe file to your hard drive.

  3. Launch Setup.exe; click Next.

  4. Make sure Install from Internet is selected; click Next.

  5. We recommend leaving the directory and other settings on this screen as they are; click Next.

  6. Now shown is a directory in which installation files will be stored; you can leave the default in place or change it, as you like; click Next. (This directory can be deleted if you wish once cygwin is installed--but if you need to update or augment your installation, it will take less time if it is present.)

  7. You are likely directly connected to the Internet (be it by dialup, DSL or an on-campus connection); if so. leave this setting as is; if you are using a proxy server (and you will know if you are), click on that choice and supply the Proxy Host and Port; click Next. (You will not want the IE5 settings, unless you routinely use Internet Explorer 5.)

  8. Choose a download site; best is one in that is likely in the states, that is, a site that does not end in a two-letter country abbreviation: closer is usually faster. Click Next. (You might get an error message from a site, such as when it is down, and be returned to the download site selection menu; if this happens, choose another site.)

  9. The Select Packages window will appear;be sure the following modules are selected (installing additional components should not hurt anything, but will require a longer download and perhaps much more disk space). To install the given component click on the category (e.g. Admin) the click on the Skip next to the service (e.g., cygrunsrv). It will change to the latest version number and bin should become checked. When you choose some selections, other components to be automatically selected; they are needed to support the chosen one. Leave them selected.

  10. Click Next; installation should commence. It can take several minutes for installation to complete.

  11. We recommend having a desktop icon and Start menu entry for cygwin, so leave the two boxes on this screen checked. Click Finish. Installation is complete; click OK.

Steps are now required to configure cygwin to provide web and database server services:

  1. Select Start -> Cygwin -> Cygwin Bash Shell (or double-click the cygwin shortcut icon on the desktop). This starts the Bash shell, giving a command line interface to cygwin's Linux emulator.

  2. You'll see a message that Cygwin is setting up some directories, and then a prompt. Type cygserver-config. When asked Do you want to install cygserver as a service? enter yes. Note the messages printed; in the next step, we set the environment variable the message discusses.

  3. Type chmod a+rwx /tmp (return) to set permissions on the tmp folder appropriate for postgreSQL use; type chmod a+rx /usr/bin /usr/bin/* (return) to set up appropirate permissions for these postgreSQL folders.

  4. Type exit , to close the Bash Shell

  5. Right-click on My Computer; choose Properties. Click the Advanced tab. Click Environment Variables. Under System Variables, click New.

  6. The Variable name is CYGWIN; the Variable value is server. Click OK; click OK again; click OK again.

Now we start up the cygserver and initialize the postgreSQL server.

  1. Start the Bash Shell again

  2. Type net start cygserver; cygwin should tell your the server was started successfully.

    You should only have to use this command this one time; the server should now be started automatically whenever you start a cygwin session.

  3. Type /usr/sbin/initdb -D /var/postgresql/data. This starts the database server, which can take a few minutes; lots of status messages will appear as the installation progresses. Eventually, you should see a message beginning Success.

    This command is issued each time you want to create a brand-new database system with another name. (So you do not need to execute it again for the database system data.)

  4. Issue /usr/sbin/postmaster -D /var/postgresql/data &. At this point the database should start (albeit possibly with a warning you can ignore).

The postgreSQL server is now running. If at some point you want to shut it down, enter control-C.

The & that ends the above command line allows you to use the same shell to interact with the the database; that is, you can "talk to" the database from this window. If you leave off the & you need to open another shell, another cygwin window, to work with the database.

You interact with the database via a program–either psql, a provided command-line interface to postgreSQL, or a program you write. (For details about psql, see www.postgresql.org/docs/8.1/interactive/app-psql.html.)


Enabling Internet access to postgreSQL

When installed, postgreSQL (by default) does not accept TCP/IP (Internet) connections to its database. Since we need to test that our database is correct and functional in a Web environment (see Phase I), we need postgreSQL to allow for TCP/IP connections to it.

By default, postgreSQL accepts connections from clinets the machine on which it resides, on your local machine; that is, IP address 127.0.0.1, domain name localhost), using port 5432. Each client is "fired up" via a commands issued in a BASH shell--so if you want at some point to simulate three users of your system coming through the Web, start up three BASH shells, one for each client, and issue the appropriate commands for each one.

If you want postgreSQL to accept connections from other computers (for example, if you are doing a demo for us on one machine, but your database exists on anohter, say a computer at home), you need to change the default:

So:

If you want to do something fancier, you will need some understanding of Internet networking and its jargon (or need to ask someone who has such knowledge) to configure things properly. You can also get more information from the comments in the file and in the postgreSQL documentation.


Enabling JDBC access to postgreSQL

Fabflixs will be using Java programs (among others) to communicate with the FabFlixs database. The Java driver that enables communication between Java and postgreSQL 8.1 databases is maintained by the postgreSQL community; we obtain it from its website:

  1. Go to http://jdbc.postgresql.org/

  2. Read the Welcome click on Download.

  3. Assuming you have installed Java 6 and postgreSQL 8.1 on your machine (as discussed above), click on 8.1-408 JDBC 3, which will download the appropriate version of the driver; you'll find it in the chart at the bottom of the web page. To be sure you have the right one, check the file name after downloading it; it should be postgresql-8.1-408.jdbc3.jar; save it to disk. We recommend putting it in its own folder at the root of C (so the path to it is short).

You can now add this file to your CLASSPATH environment variable -- the string is

;C:\yourFolderName\postgresql-8.1-408.jdbc3.jar

Note the ";", which separates this CLASSPATH entry from the previous one.

if you want it available every time you compile a Java program. (Be sure there is a ";" between it and the previous entry in the classpath.) Or, you can place it into the CLASSPATH switch on the javac command line when you need it (which is whenever you run a java class that uses JDBC commands); for example, if the program to run is PostgresJDBC then the command line is

java -classpath .\;C:\yourFolderName\postgresql-8.1-408.jdbc3.jar PostgresJDBC

Note the need for including .\ --the current directory -- in the classpath. It is not included automatically, as the classpath switch completely overrides any default or classpath environment variable settings.

If you want to add something to your existing classpath for just this compile, start the -cp parameter with %CLASSPATH% -- and since the existing classpath may have spaces in its file names, enclose the parameter in quotes; e.g.,

java -classpath "%CLASSPATH%;C:\postgresql-8.1-408.jdbc3.jar" PostgresJDBC

To test that this connection works, we create a tiny test database and run a small Java program that uses JBDC to "talk" to it.

  1. Start a Bash shell (if a client shell is not already open); start the database (if you've not already done so -- /usr/sbin/postmaster -D /var/postgresql/data &
  2. Create a user; you enter the commands in that appear in italics:

psql is an interactive tool that allows the user to issue SQL commands to a database and to obtain information about the database itself, known as meta-data. basic psql meta-commands you might find useful during this phase include

Now enter postgreSQL as testuser and create a database with a small table with one entry. .Be sure to use the -U (user) switch; if you don't . it assumes, on most machines, the user is "administrator," which can result in only adminstrators having access to the changes you made. Similarly, if you do not connect to the moviedb (\c moviedb below), the tables you create will not be associated with the movie database, causing problems down the road.

Now enter and compile the following java program; it uses JDBC to communicate with your test database and retrieve some basic information about it. Study it to get a feel for how JBDC works. (This is just a test program; a production program would clean some things up, such as not throwing an Exception out of main()!)

import java.sql.*;

public class PostgresJDBC
{
 	public static void main(String[] arg) throws Exception
	{
		Class.forName("org.postgresql.Driver").newInstance();
 		Connection connection = DriverManager.getConnection(
 		"jdbc:postgresql://localhost/moviedb", "testuser", "testpass");
 
 		Statement select = connection.createStatement();
		ResultSet result = select.executeQuery("Select * from stars");
  		System.out.println("The results of the query:");
 		ResultSetMetaData metadata = result.getMetaData();
 		System.out.println("There are " + metadata.getColumnCount() + " columns");
 
 		for (int i = 1; i <= metadata.getColumnCount(); i++)
 			System.out.println("Type of column " + i +" is " + metadata.getColumnTypeName(i));

 		while (result.next())
 		{
 			System.out.print("id = " + result.getInt(1));
 			System.out.println(" Name = " + result.getString(2));
 		}
 		connection.close();
	}
}

Replace localhost with the IP address of the computer you are using, if it is not the same machine on which the database resides.

Note that you can write, compile and run the Java code in Windows and have it communicate with the postgreSQL database, even though the latter is running under a Linux shell.


Installing and testing Tomcat

To support dynamic content on web pages and Java servlets (extensions of a server's basic services), we use Tomcat, a freeware package form the Apache Software Foundation. (You will be using its capabilities starting in Phase 2.) To install Tomcat

  1. Go to http://jakarta.apache.org/tomcat/; read a bit!

  2. Under Download, click on Tomcat 6.x (look on the left-hand side of the page).

  3. Under 6.0.10, select Windows Server Installer under Binary Distributions, Core; save the EXE file.

  4. Launch the EXE file you just downloaded.

  5. Read the instructions; click on Next; read the license and agree.

  6. On this screen, make sure Tomcat and Start Menu Items are checked. Leave Documentation checked if you want the documentation on your drive (it is also available at the Tomcat site); check Examples if you want some examples of servlets. Click Next.

  7. Leave the destination folder as is; click Next.

  8. Leave the port at 8080--this is crucial. Choose an administrator login name and password: do not forget them! Click Next.

  9. Check that the directory listed is indeed where you have the java virtual machine (java.exe and its associated files) stored; if you used the default directories for java when installing it above, it is C:\Program Files\Java\jre1.6.0_01. Click Install.

  10. Wait a few minutes while installation occurs.

  11. Click Finish. A window should appear showing Tomcat starting up; the release notes file should appear in a window.

Check over the release notes (and them close them). To be sure Tomcat is running, right click on the feather-like icon in the lower right of the Windows toolbar (if you hover over the correct icon, Apache Tomcat will appear); Start service should be grayed. To stop Tomcat at any time, right-click on the icon and select Stop service. You can also start and stop Tomcat on the General panel of the Configure Tomcat application (Start -> All Programs -> Apache Tomcat 6.0 -> Configure Tomcat).

To test that Tomcat is working and communicating with postgreSQL properly, we've prepared a servlet that performs basically the same tasks as the JDBC program; it queries the test database and returns some structural and content information. To run this program:

  1. Make sure the postgreSQL database server is running template1 (BASH command /usr/sbin/postmaster -D /var/postgresql/data). Be sure to set up the test database as described in Enabling Internet access to postgreSQL, above, before proceeding.

  2. Download TomcatTest.war

    A WAR file is a "Web Application Archive." It contains a compressed directory of the files needed for a ready-to-run java servlet that Tomcat will launch when you go to the Web page designated in the WAR. (A WAR file must a have certain directory structure and contain appropriate files (with the appropriate contents) for Tomcat to launch the applet. Details about WAR files will be covered in Phase 2.)

  3. Go to http://localhost:8080; this is your local web page. After installing Tomcat, it was set to the Tomcat welcome page; that page should appear.

  4. Click on Tomcat Manager; enter your admin user login and password (given when you installed Tomcat); click OK. If your login and password are correct, the Tomcat Web Application Manger page will appear.

  5. Under War file to deploy, enter in or Browse to find the location of TomcatTest.war; then click the Deploy button. This action decompresses the WAR and places its folders into their required locations. TomcatTest should now appear in the Applications list.

  6. Go to http://localhost:8080/TomcatTest/servlet/TomcatTest. Tomcat will run the servlet TomcatTest and print its output onto the web page. If the output is database information, all is well. If instead you see a message that an SQLException occurred, check that the postgreSQL server is running, that it is configured to allow TCP/IP access and that the test database with the correct user name, user password and table structure has been created (see above).


Installing the Google Web Toolkit

We will use The Google Web Toolkit, or GWT, to help in developing the AJAX aspects of FabFlixs in Phase 5. GWT "...lets you escape the the matrix of technologies that make writing AJAX so difficult and error prone. With GWT, you can develop and debug AJAX applications in the Java language using the Java development tools of your choice." [What is Google Web ToolKit, code.google.com/webtoolkit/overview.html]

To install GWT:

  1. Go to the Google Web Toolkit Downloads web page.

  2. Click on Download Google Web Toolkit in the gray box; save the presented zip file to disk. This will download the latest version of GWT for the operating system of the computer linking to the page.

  3. Unzip the file; you're done! "GWT does not have an installer application. All the files you need to run and use GWT are located in the extracted directory." [Google Web Toolkit Getting Started Guide, code.google.com/webtoolkit/gettingstarted.html]

You are now ready to proceed with FabFlixs development.


Setting Up Windows XP Computers for a Remote Demonstration

If you plan to do your demontrations by connecting an XP computer at a meeting place to a remote XP computer that houses the software to be demonstrated, follow the isntructions on the Get started using Remote Desktop with Windows XP Professional web page. Some additional things to keep in mind:

Written for ICS185 Spring 2005 by Norman Jacobson, March 2005.
   Some sections adapted from ICS185 Winter 2005 exercises written by Chen Li, and sample code and FAQs written by Chen Li and Kirill Petrov.
Updated for CS122B Spring 2007 by Norman Jacobson, March 2007.
   Some provided information was obtained from the CS122B Winter 2007 'Fabflix: Project Setup the development environment' and 'FabFlixs: Project 5' web pages.