tgds.net

Using Macromedia UltraDev with PostgreSQL, Tomcat and Apache

Tony Grant 2001
Additional material from Justin Clift, Peter Mount and members of the PostgreSQL-general mailing list

Dreamweaver MX page

Macromedia UltraDev is a RAD for web applications running on ASP, ColdFusion or JSP application servers. We have been running the PostgreSQL database system since 1997. Our objective is to use this RAD environment to develop simple web applications using the Tomcat JSP application server with Apache and PostgreSQL database software running on Linux powered servers.

Binary versions of all software were preferred in this example. Our objective is to make the process as simple as possible for non programmers. However basic knowledge of Linux file system layout is required.

Most of the following is in the docs. Our goal is to get the essential information together in one place - please use this as a "cheat-sheet". This document does not replace a good long read of the docs, especially the PostgreSQL user manuals and the UltraDev "Using UltraDev" book. They are very good, read them now before going any further.

The hardware:

A Linux database server and a web application server. This should be two separate machines in a production environment - one for the database system and another for the web application server. In our development environment both servers run on the same machine.

The software:

Our examples are based on the RedHat 7.0 distribution. If you are already running another distribution you will have the knowledge required to modify the path to suit your set up.

Apache web server - latest rpm version from RedHat

JDK1.3 - latest 1.3.0_2 binary version from Sun

Jakarta Tomcat Java application server - 3.2 binary for RedHat 7.0 from Apache.org ftp server

Ant - latest rpm from Apache.org ftp server

mod_jk.so - precompiled from Apache.org ftp server

PostgreSQL - 7.1 rpms from PostgreSQL.org ftp server

A working ftp server - one from the RedHat distribution

Installation:

Change to the root account to install the rpm and binary packages

Install the JDK.

Then:

cd /usr/java
mv jdk1.3.(version_number) /usr/Java/jdk1.3

Modify /etc/profile to include the path to the JDK /usr/Java/jdk1.3

Install Apache

Copy the mod_jk.so to the directory containing the other modules.

Install Tomcat

CD /usr/local
MV jakarta-tomcat-xxx /usr/local/tomcat

Install Ant

Install PostgreSQL

The JDBC driver, PostgreSQL.jar, should be copied to /usr/local/tomcat/lib. Thanks to Justin for the heads-up on this one.

Finding the bits and pieces, downloading and putting them all together took about half a day, so plan ahead.

Configuration:

The difficult part! It took me some time to figure out Tomcat configuration because when you install the linux binary you also get all the bits and pieces for NT. IIS and Netscape server configuration files are also in there... Do not follow the Tomcat mod_jserv installation instructions! Follow mod_jk install instructions, they are the ones that are required in our case. Read them carefully and modify your httpd.conf file to load the module:

LoadModule jk_module modules/mod_jk.so
AddModule mod_jk.c

My Apache modules are in the modules directory under the Apache tree. Restart Apache and check to see if your module loads correctly.

Where to install your web applications:

Install your application root folder in /usr/local/tomcat/webapps/yourappname.

TIP -do not call your test app "test"! There is already an app called test in the webapps folder.

Create a tomcat user and group and make them the owner of the folder /usr/local/tomcat/webapps/yourappname

Set /usr/local/tomcat/webapps/yourappname as the ftp root for your tomcat user account.

Files to modify now are:

/etc/httpd/conf/httpd.conf

JkWorkersFile /usr/local/tomcat/conf/workers.properties
JkLogFile /usr/local/tomcat/logs/mod_jk.log
JkLogLevel warn
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13

Alias /examples "/usr/local/tomcat/webapps/examples"
<Directory "/usr/local/tomcat/webapps/examples">
Options Indexes FollowSymLinks
</Directory>

JkMount /examples/servlet/* ajp13
JkMount /examples/*.jsp ajp13

<Location "/examples/WEB-INF/">
AllowOverride None
deny from all
</Location>

<Location "/examples/META-INF/">
AllowOverride None
deny from all
</Location>

Alias /admin "/usr/local/tomcat/webapps/admin"
<Directory "/usr/local/tomcat/webapps/admin">
Options Indexes FollowSymLinks
</Directory>

JkMount /admin/servlet/* ajp13
JkMount /admin/*.jsp ajp13

<Location "/admin/WEB-INF/">
AllowOverride None
deny from all
</Location>

<Location "/admin/META-INF/">
AllowOverride None
deny from all
</Location>

Alias /yourappname "/usr/local/tomcat/webapps/yourappname"
<Directory "/usr/local/tomcat/webapps/yourappname">
Options Indexes FollowSymLinks
</Directory>

JkMount /yourappname/servlet/* ajp13
JkMount /yourappname/*.jsp ajp13

<Location "/yourappname/Connections/">
AllowOverride None
deny from all
</Location>

Here we have stopped access to the folder containing configuration details for your UltraDev connection, including the password for the database... I tried protecting the _mmDBScript folder too, but doing so prevents UltraDev from writing to it during development. Do we need to protect this folder when we deploy the application? Security experts please chip in here...

/usr/local/tomcat/conf/server.xml

Modify the « Connectors » section at the bottom by adding

<Connector className="org.apache.tomcat.service.PoolTcpConnector">
<Parameter name="handler" value="org.apache.tomcat.service.connector.Ajp13ConnectionHandler"/>
<Parameter name="port" value="8009"/>
</Connector>

Add the context for your application:

<Context path="/yourappname"
docBase="webapps/yourappname"
debug="0"
reloadable="true" >
</Context>

Last of all /usr/local/tomcat/conf/workers.properties must be modified for your Linux set up.

Then:

export TOMCAT_HOME=/usr/local/tomcat
export JAVA_HOME=/usr/java/jdk1.3

The last line is not necessary if you reboot your machine. We modified /etc/profile earlier on remember.

Start Tomcat then restart Apache. Now all requests to http://localhost/examples/ should be sent to Tomcat. Test that everything works before going any further!

Configure PostgreSQL to accept Tcp/IP connections and to allow the database owner to connect from the application server machine. Start PostgreSQL as per instruction in the PostgreSQL documentation. Create your database and try connecting to it.

Connecting from UltraDev:

This has been tested from the Windows version of UltraDev 4.0. It works with the Mac version too.

A good idea is to do the UltraDev tutorial from start to finish. Once done you have all the basic knowledge you need to move on to your own custom applications.

Modified files to put in your UltraDev Configuration folder:

\Configuration\Connections\connections.xml

\Configuration\Connections\JSP\Win\postgresql_jdbc_conn.htm

To install; right click on the above link and save to your Configuration folder.

Here is my Application Server Site Definition dialogue. You will need to add your FTP Host IP number. The Host Directory will be blank because in your FTP server configuration you have defined the /usr/local/tomcat/webapps/yourappname as the server root for the FTP user "tomcat". The URL Prefix is the same as the Context Path above, or http://localhost/yourappname

Now after opening a page in the web application you are building we shall define a connection. Name it connYourappname to make it easy to identify. The User Name and Password are the ones you use to connect to the database and are probably different from the FTP user defined above. (This stumped me first time around). UltraDev will use the JDBC .jar file in the tomcat/lib directory. Another thing I did wrong was to have a copy of the PostgreSQL.jar file in my JDK tree. It did not work for me.

I managed to follow all of the UltraDev Tutorial with a database I had built previously. I changed the references to the fields used in the tutorial to match my situation. Maybe soon we can convince Macromedia to put a PostgreSQL 7.1 pg_dump file of their tutorial base on their FTP site...

Conclusion:

Using UltraDev to build JSP based web applications is about as simple as it gets. The apps run on any java capable browser. The RAD requires no prior knowledge of the Java language. It does require some knowledge of SQL - but the SQL primer in the PostgreSQL docs covers this quite well.

If you wish to go further, Java knowledge is a must.

All questions concerning this HOWTO should be addressed to the postgres-general mailing list.

Version français

All trademarks, brand names etc. used on this page are probably registered and owned by the companies mentioned herein.

31-août-2005 © tgds 2005 | tgrant@tgds.net | Privacy | Conditions de vente