As the first part of the project you will set up the development environment that will be used throughout the project. The steps for this part are listed below.
The message forum will contain a number of servlets and/or JSP pages that must be executed in a web server. In order to create a realistic environment (and to avoid clashes between different lab groups), each lab group will be running its own instance of the Caucho Resin web server.
Start by installing the Resin configuration files in your home directory. This is done only once!
This creates a directory called resin in your home directory. You must also add the resin module:
module add /home/TDDI48/modules/resin/3.0.17 module initadd /home/TDDI48/modules/resin/3.0.17
Before you actually start using Resin, you must configure it to use a unique port number that will not clash with the port numbers used by other people that may running servers on the same computer that you use (remember that the SunRay computers are thin clients, "terminals" connected to central servers). Change ~/resin/conf/resin.conf as follows. First, locate the line saying <http server-id="" host="*" port="8088"/> and change the port number from 8088 to another random number . Second, completely delete the following lines from the configuration file:
<cluster> <srun server-id="" host="127.0.0.1" port="6802" index="1"/> </cluster>
To start, stop, and restart Resin, use the following commands:
~TDDI48/bin/resin.sh start ~TDDI48/bin/resin.sh stop ~TDDI48/bin/resin.sh restart
After installing Resin, make sure that it works correctly by
pointing your browser to
The web page you see is taken from the webserver root resin/doc that contains an example index.html file.
The main configuration file is in resin/conf/resin.conf. Here you can set things like the http port, or configure locations of log files.
TOOLS: Note that you should be using Mozilla or Firefox as a web browser. These are currently the most standards-compliant browsers available on the Sun machines. Opera might also be a good choice if it is available on your machine. Internet Explorer is not recommended, due to its poor support for CSS and other standards.
The message forum will be written as a single Java/JSP web application. There is already one web application configured in Resin, the default web application, which serves files from the ~/resin/doc directory. This web application was configured in ~/resin/conf/resin.conf as follows:
<document-directory>doc</document-directory> <!-- configures the root web-app --> <web-app id='/'> <!-- adds xsl to the search path --> <class-loader> <simple-loader path="$server-root/xsl"/> </class-loader> <welcome-file-list> <welcome-file>index.xtp</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
Your message forum web application should of course be a separate web application, not mixed up with the default application. Though you won't be writing any servlets or JSP documents just yet, you will soon begin writing some HTML web pages and forms, so we'll have to start configuring the web application right now.
As a first step, create a directory for the web application: ~/resin/doc/tddi48.
Right now the server only considers this to be an ordinary directory within the
default webapp. To make it a separate webapp, add the following to ~/resin/conf/resin.conf, after the default webapp configuration
<web-app id="forum" document-directory="tddi48"/>
Create a very simple "hello world" web page at ~/resin/doc/tddi48/index.html. You will write a better page later, so don't spend much time on it.
If you wait a minute, Resin should discover that you changed its configuration file. Resin should automatically restart. Some versions of Resin also indicate this by printing "Resin httpd restart at..." to the window from which you started it.
If you don't want to wait a minute, run ~TDDI48/bin/resin.sh restart to restart the server manually. (If you keep getting "Resin httpd restart at..." messages, you made a mistake in the configuration file; check the logs in ~/resin/logs and try to find out where the error is.)
When Resin has finished restarting (which might take 10 seconds after the message is
printed), try taking a look at
http://localhost:yourChosenPortNumber/forum/. The context
path /forum should now be mapped to the tddi48 directory, and you will see your new index.html document.
(Why does the server send index.html when you asked for the forum/ directory? Because resin.conf has a reference to app-default.xml, and app-default.xml specifies a <welcome-file-list> that includes index.xtp, index.jsp, and index.html. You can change this in your own webapp if you want the default "welcome page" to be called something else.)
If Resin has not already done this for you, you should also create a directory called ~/resin/doc/tddi48/WEB-INF. This directory will be used when you start doing more complex tasks with your web application. For example, servlet code and the web.xml deployment descriptor will go into this special directory. For now, you can leave the WEB-INF directory empty.
If you decide to use IDEA (which we strongly recommend), you will have to install the IDEA configuration files and set up a project.
Before you use IntelliJ IDEA you must install the IDEA configuration files in your home directory. This is done only once!
This creates a directory called .IntelliJIdea60 in your home directory and copies some configuration files to that directory.
You must also add the JDK 5.0 module:
module add prog/jdk/5.0 module initadd prog/jdk/5.0
Several versions of IDEA have been installed in parallel. New updates will be installed as they are released and will be announced on the course home page.
At the time of writing, the most recent version is IDEA 6.0.4 build 6148. To start it, use the following command:
If new versions of IDEA are installed, you may have to change this command line to reflect the new version number.
You will have to provide quite a lot of information in order to configure IDEA for your project, but fortunately this only has to be done once. Please make sure that you follow these instructions carefully! Print them out, and mark everything you have done so you don't lose your place and miss a step. If anything is unclear, please ask us.
Create a new project using. If this is the first time you start IDEA, the New Project dialog may appear automatically.
Give the project a suitable name, preferably without Swedish letters ňń÷┼─Í (just in case...), for example "Project" or "Meddelandeforum".
Then tell IDEA the location where you want to save the project, for example in /home/noone123/tddi48/project/ or /home/noone123/tddi48/Meddelandeforum/. You can type the path manually or press the "..." button to select a path. In the resulting dialog window, you can press the folder-with-a-star toolbar button to create a new folder.
You will be asked for a compiler output path where IDEA will place compiled classes. You should place these classes in /home/noone123/resin/doc/tddi48/WEB-INF/classes, where the Resin application server will find them.
The next thing to specify is the JDK (Java Development Kit) to be used with your project files. Please use the newest version of JDK 1.5.x / 5.x available (at the time of writing, this should be JDK 1.5.0_10). If no version of JDK 1.5 is available, use the "+" button to add a new JSDK and select /sw/jdk-1.5.0_10 in the file dialog.
An IDEA project consists of one or more modules. You have now finished specifying the "global" project settings, and it is time to configure a module containing your web application.
When IDEA asks you whether you want to configure a module, select "Create single-module project".
Since you will be creating a web application, you should create a web module. Select Select module type / Web Module.
Give the module a name. In order to make it easier to distinguish between the module and the project you might want to give it a distinct name such as "ForumModule".
Specify the content root for the module. This is the location where all the files related to the module are stored. By default, this may be the project directory itself, which is not a good idea in case you may want to add more modules later. It should be a subdirectory within the project directory.
For example, if your project directory location was /home/noone123/tddi48/project/, the content root should be something like /home/noone123/tddi48/project/ForumModule.
Now IDEA wants to know where the web.xml deployment descriptor should be located. You can accept the default location, since you don't have an existing deployment descriptor. Use version 2.4 of the deployment descriptor.
IDEA also wants to know where web resources will be stored. Web resources are basically all files that should be provided to the web server except servlet class files – that is, JSP or HTML documents, images, and other information that the web server will use. These files will be developed and edited in a development directory in IDEA (within /home/noone123/tddi48/project/). When you have successfully compiled your project, IDEA will automatically deploy the web application by copying the servlet classes and the web resource files to the web server's deployment directory (~/resin/doc/tddi48).
The module wizard lets you specify a single web resource directory. The default is a resources directory in the content path of your web module: /home/noone123/tddi48/project/ForumModule/resources in our example. You could keep this default value.
At "Relative path in deployment directory", you determine the destination relative to the deployment directory ~/resin/doc/tddi48. You should leave the default "/" to indicate that files in /home/noone123/tddi48/project/ForumModule/resources should be copied to ~/resin/doc/tddi48.
You will now have to specify an exploded directory location. This is the location where IDEA will copy your files once you have successfully built (compiled) your project. Do not use the default. Change this to /home/noone123/resin/doc/tddi48/, the root of the web application deployment directory you created when you configured the web server.
A module can contain Java source files as well as other related files. In this step, IDEA wants to know where your source files are located. It is safe to accept the default, that is, to create a src subdirectory inside the module directory.
Pressto create the new project.
When you have finished the New Project wizard, there are a few more things to configure in the Paths dialog. Open this dialog by using.
The next step is to specify an application server (web server) where the web application will be executed. Click theicon. The application server is Resin, and IDEA has no default setup for Resin.
Press Generic from the drop-down menu. This adds a new "blank" application server configuration.and select
Rename the new application server to something reasonable such as "Resin".
Tell IDEA where the
javax.servlet package is located. Click
and add the JavaServer Development
Kit jar file, /home/TDDI48/misc/resin-3.0.17/lib/jsdk-24.jar.
IDEA will also want to be able to find some classes related to Enterprise JavaBeans. Though you won't use those classes in your projects, you could still add /home/TDDI48/misc/resin-3.0.17/lib/ejb-20.jar to the project in order to avoid warnings.
Click OK to dismiss this dialog window.
You should configure some class libraries that will be used in your project. IDEA libraries can be configured at three levels: At the module level, at the project level (available for all modules in a project), and at the global level (available for all projects). For this course, you can configure these libraries as global libraries.
You will definitely need to use the Connector/J JDBC driver. Open the "Global
Resources" node, right-click the "Global libraries" and select "Add Global
Library". Type in a name for the library
("Connector/J"), and select the JAR file
/home/TDDI48/jar/mysql-connector-java-3.1.12-bin.jar in the tree
dialog. Press . The library should turn up in
the "Global Library" dialog.
You may also need to use JavaMail, which
requires two different JAR files. Add another global library and type in the name
"JavaMail". Select the JAR file
/home/TDDI48/jar/javamail-1.3.2.jar in the tree dialog. Press "OK".
Now add the other JAR file
/home/TDDI48/jar/activation.jar (the JavaBeans Activation
Framework) using the button . The JavaMail library now consists of
two JAR files.
In the "Project / Modules / ForumModule" node there is a "Dependencies" tab where you should add the global libraris you've just created and the Resin application server.
Another tab is the "Web Module Settings" tab where you can fill in some of the web application properties that will be stored in web.xml. (Don't worry if the deployment descriptor path is red. This will change once web.xml is created.)
Under the "Modules and libraries to package" headline, you can specify which class libraries your servlets and JSP code will need to use. These libraries will automatically be copied to the WEB-INF/lib directory (to be more exact, /home/noone123/resin/doc/tddi48/WEB-INF/lib) when you deploy the web application.
Please make sure that Connector/J and JavaMail are marked as "Copy files to". You can accept the default relative path: WEB-INF/lib. Resin will automatically check for libraries in this location when executing servlets or JSP code.
The Resin configuration should be marked as "Do not package". Resin already has these classes and does not need a second copy!
Under "Web Resource Directories", you see the resource directory you configured in the wizard. You should not have to change this.
You can now press, close the settings window, and finally start working with your project.
Take a look at the files available under the Project tab in the project pane (if it is not visible, selector click the "1: Project" tab on the left hand side of the screen).
You should see your src and resources directories there. The src directory is blue, to indicate that it can contain Java source code. You should also see a web.xml file, though it may not contain much yet.
Also take a look at what is available under the J2EE tab of the project pane. The J2EE tab permits you to access web-specific functionality.
As you can see, the src directory that you created previously is not shown here. This is a web application view, which shows servlet configuration items (once you have added them) but not general Java classes. On the other hand, the resources directory is shown, though it looks a bit different. It is blue, with a tiny yellow-and-blue globe, indicating that it is a web resource directory.
In the J2EE tab, double-click the ForumModule (a blue-and-yellow globe). The result will be a property page where you can configure servlets and a few other properties related to the web module.
Fill in a display name, such as "FooSoft Message Forum".
Fill in a description for your message forum web application.
You should not check "distributable". This is for web applications that can be distributed over multiple computers in a cluster.
Note that there is no "OK" or "cancel" button. The property page is saved along with other information when you "save all".
Double-click web.xml, and you will see some of the
configuration properties that you specified previously. If you ctrl-click one of
the tags (such as
<description>) you can see its definition in
the deployment descriptor DTD. There are also comments describing how each tag is
If web.xml is almost empty, IDEA may not yet have saved your display name and description to this file. Press Ctrl-S and see whether the file changes.
You should now start the database server and create a database together with a table in which user information should be stored.
In this lab, we will be using the MySQL database
server. To use MySQL, you must add the module
You may also want to initadd the module, so that it is always available when you log
module add office/mysql/4.1.7 module initadd office/mysql/4.1.7
You might also have to run the built-in shell command
rehash to make
the shell update its internal caches (otherwise it might not find the
temp_mysqld commands even though they
really are in your path).
(MySQL 5.0.22 is also installed on the lab computers. You may use this version if you wish, but it has not been tested in the forum project and you are unlikely to need any of the new features available in MySQL 5.)
The first time you use the database server, you must create a configuration file where you define a port number to be used and a location for the mysql.sock special file. The reason why this must be done manually is that many of you may end up running on the same computer, and each of you must be running your database server on a unique port number.
To configure these settings without having to give additional arguments to mysql for every invocation, you should create a new file called ~/.my.cnf where you add the following items:
[client] port=47111 # choose a random number socket=/home/noone123/mysql.sock # noone123 = your email [mysqld] port=47111 # same as above socket=/home/noone123/mysql.sock # same as above
The port number that you chose at random will also have to be used in JDBC URL
you use in your database classes. A JDBC URL for MySQL has the form
jdbc:mysql://[hostname][:port]/[dbname], where the port number is
the same one you specified in .my.cnf.
Once you have created the ~/.my.cnf file as described above, you also have to create a few system tables and create a new database. You can do this as follows:
mysql_install_db — this creates a new directory
~/mysql where all database information will be stored and creates
some configuration files in that directory. You only do this once.
In a new xterm window, start
temp_mysqld (in the foreground; don't
&" or the server may not terminate when you log out).
This is the MySQL server; it must be running whenever you want to access your
Set the root password — for example,
mysqladmin -u root password 'tjohej'.
Create a new database:
mysqladmin --user=root --password=tjohej create
forumdb, if you used the password
tjohej above and you want
to call the database
Next time you want to use the database, you will only need to start
temp_mysqld (still in the foreground; don't use
To learn more about using the command line program
mysql and the MySQL
database in general, you can read the documentation available at the MySQL web site. You can also read the following
two brief tutorials (not written by the authors of MySQL): Beginning
MySQL Tutorial and MySQL Basics. More
articles on MySQL are available at DevShed.
(Continued in part 2 of the project...)
[Check links]Jonas Kvarnstr÷m