Wednesday, May 14, 2008

My first webapp, Walkthrough pt2: Server configuration

In order to prepare a system for the db-enabled webapp, follow the steps below:
  1. Download+install Java (preferrably Java6 SDK). Setup $JAVA_HOME environmental variable accordingly, so that $JAVA_HOME/bin/java is the JVM executable. For linux, package managers now offer sun-java-* packages, you'd better AVOID the gcj stuff, for maximum compatibility.
  2. Download+install MySQL. Again, linux distros have packages in default repos. Edit the MySQL configuration file (/etc/mysql/my.cnf or whatever), so that, under "[mysqld]", you COMMENT the "skip-networking" option and give a good bind address ( is safest). Part of the file will look like
    user = mysql
    pid-file = /var/run/mysqld/
    socket = /var/run/mysqld/mysqld.sock
    port = 3306
    basedir = /usr
    datadir = /var/lib/mysql
    tmpdir = /tmp
    language = /usr/share/mysql/English
    bind-address =
    # skip-networking
    The example listens only on the local loopback interface, change for use with remote tomcat. In general, test access to your mysql daemon with "telnet localhost 3306", or such.
  3. Download+install Tomcat-5.5, preferrably the zip package. Linux distros offer tomcat packages. Consider $CATALINA_HOME to be the installation path, so that $CATALINA_HOME/bin/ starts the server. Tomcat requires special administration:
    1. Download the MySQL JDBC connector, and place the JAR file in $CATALINA_HOME/common/lib, for all webapps to see. Keep in mind that the MySQL driver class is com.mysql.jdbc.Driver.
    2. See to that the Security Manager lets the driver create a socket to the listening server port, by adding a policy entry to $CATALINA_HOME/common/conf/catalina.policy:
      grant codeBase "jar:file:/path/to/tomcat5.5/common/lib/mysql-connector-java-5.1.5.jar!/-" {
      //permission "localhost:", "connect";
      //permission "", "connect";
      //permission "", "resolve";
      permission ;

  4. For development, NetBeans 6.1 is good, Eclipse offers some not-so-good plugins, and Vi is always a safe choice.

Friday, May 09, 2008

My first webapp, Walkthrough pt1: Requirements

This is the first entry in a series of post that guide through the creation of a tomcat (tomcat-5.5) web application with the following features:
  1. Database connectivity (mysql-5)
  2. User authentication (a simple one, not JAAS stuff)
  3. User-created database content
  4. Universal foreign language support in forms, parameters and files (utf-8 encoding)
  5. File creation/manipulation
I consider a java-6 based system, and will report which things differ with standard java-1.4 cases (usually the encoding stuff). There will be no reference to the development tools, since this walkthrough aims at full understanding of every potential change to the configuration of the involved software subsystems. I would suggest any linux flavour for this. My configuration:
  • Linux Mint 4.0 (ubuntu-7.10 based)
  • Sun Java 6u6 (from apt-get)
  • Tomcat 5.5 (from apt-get)
  • Mysql 5.1 (from apt-get)
The Walkthrough pt2 will hold important configuration parameters of the installed software

Tuesday, May 06, 2008

Rollback with svn

Trickier than it may seem, but simpler than expected. This is how you revert/rollback to an earlier svn version and cancel/undo all the stupid things you have done. Example:
Assume: $STUPID_VERSION is the version that messed things up, $LOCALMODIFIEDDIR the place where things change (must be svn-controlled of course, but can be a subdir of the project, if this is desired)

$ svn merge -c -$STUPID_VERSION .

Note the dot at the end '.'; Found here, at this good guy's blog.
.. oh, and NEVER NEVER NEVER copy entire svn-controlled directories!!! the ".svn" hidden dirs are chaotic evil.

Now, it's quite probable that a future commit will result in failure because of "file already exists"... Therefore, make a local copy of the affected $LOCALMODIFIEDDIR somewhere without svn (let it be $BACKUPDIR), DELETE the ".svn" inside, and:

$ svn delete --force $LOCALMODIFIEDDIR
$ svn commit -m "deleted the dir"
$ svn add $NEWDIR
$ svn commit -m "stupid error fixed "

So simple... :-(