Saturday, 12 May 2007

Blojsom + Jetty + Postgres

Main | Swing/NetBeans development impressions »

Blojsom is a great java based blogging webapp that I got up and running today. 

Here's my guide as to how to set it up:

Setting up Blojsom 3.2 on Postgres/Jetty

  • Download Blojsom Quickstar Bundle

    http://sourceforge.net/project/showfiles.php?group_id=72754&package_id=125988

  • Download Jetty 6

    http://dist.codehaus.org/jetty/jetty-6.1.3.zip

  • If Postgresql has not been installed you can get it from:

    http://www.postgresql.org/

    if you are on Debian or Ubuntu simply run

    apt-get install postgresql
Now on to the install
  • from your home directory - assuming your site is called xclu.com:
    mkdir xclu.com 

    unzip jetty-6.1.3.zip

    declare -x JETTY_HOME=~/xclu.com/jetty-6.1.3/

    cd $JETTY_HOME

    Get the appropriate Postgresql driver from

    http://jdbc.postgresql.org/download.html

    to get your version

    psql --version

    copy it to $JETTY_HOME/lib/ext/

    cd webapps

    mkdir blojsom

    cd blojsom

    jar -xvf ~/xclu.com/blojsom.war

    edit $JETTY_HOME/webapps/blojsom/WEB-INF/classes/blojsom-helper-beans-include.xml

    Replace the datasource with an appropriate postgresql configuration. You probably want to use a better password than 'blojsom'.:



    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://localhost/blojsom"/>
    <property name="username" value="blojsom"/>
    <property name="password" value="blojsom"/>
    </bean>

    Modify the dialect

    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>

    Edit $JETTY_HOME/webapps/blojsom/WEB-INF/classes/blojsom.xml

    Modify the dbloader


    <bean id="dbloader" class="org.blojsom.util.database.DatabaseLoader" init-method="init">
    <property name="sessionFactory">
    <ref bean="hibernateSessionFactory"/>
    </property>
    <property name="dbScript" value="/WEB-INF/classes/blojsom-full-initial-data-postgresql.sql"/>
    <property name="upgrading" value="false"/>
    <property name="servletConfig">
    <ref bean="servletConfigFactoryBean"/>
    </property>
    <property name="detectBlojsomSQL">
    <value>select relname from pg_stat_user_tables where relname = 'blog';</value>
    </property>
    </bean>

    Create the blojsom database (may need to be done as postgres user account if you haven't created a postgres superuser account for yourself)

    createuser blojsom

    Answer no to whether the user should be allowed to create databases or other users

    createdb -O blojsom blojsom

    psql blojsom
    blojsom=# alter user blojsom with password 'blojsom';
    blojsom=# \q

    To allow local acess to your database edit pg_hba.conf and add the following line right underneath the IPv4 comment.

    # All IPv4 connections from localhost
    host blojsom blojsom 127.0.0.1 255.255.255.255 md5

    Restart postgresql

    Test the configuration

    psql -h 127.0.0.1 -U blojsom -W blojsom

    login with password "blojsom"

    You should get the follow prompt

    blojsom=>

    exit the psql client

    blojsom=> \q

    Set the hostname and port in $JETTY_HOME/etc/jetty.xml properly

        <Call name="addConnector">
    <Arg>
    <New class="org.mortbay.jetty.nio.SelectChannelConnector">
    <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
    <Set name="maxIdleTime">30000</Set>
    <Set name="host">www.xclu.com</Set>
    <Set name="Acceptors">1</Set>
    <Set name="statsOn">false</Set>
    <Set name="confidentialPort">8443</Set>
    <Set name="lowResourcesConnections">1000</Set>
    <Set name="lowResourcesMaxIdleTime">500</Set>
    </New>
    </Arg>
    </Call>

    Replace localhost:8080 with whatever your actual hostname is. In this case my hostname is 'www.xclu.com'

    Change the jetty sql scripts so they initialize the database with the right hostname

    perl -pi -e 's/localhost:8080/www.xclu.com/g' $JETTY_HOME/webapps/blojsom/WEB-INF/classes/*.sql

    Run Jetty!

    cd $JETTY_HOME
    ./bin/jetty.sh start

    Now go to

    • You may now access your blog at http://your-blojsom-install-site/blojsom/blog/default/
    • You may access the administration console at http://your-blojsom-install-site/blojsom/blog/default/?flavor=admin
    • The default user and password is default/default. Be sure to change the password immediately after logging in. You can change this under Weblog Settings | Users.

Technorati Tags:

Posted by justin at 11:51 PM in Java Programming

 

[Trackback URL for this entry]

Comment: Tim at Sun, 13 May 11:23 AM

Excellent notes.

I liked especially the editing the initial db loader to drop the use of 8080. This was something where I had to take a wire brush to my SQL skillz (being as rusty as they are) to change (my fumbling with the UPDATE syntax was laughable last night).

Funny thing about hindsight, I should have just turned on the Connector for port 8080 in Tomcat, then I could have edited it over the admin console. Such is life.

Your comment:

(not displayed)
 
 
 

Live Comment Preview:

 
« May »
SunMonTueWedThuFriSat
  12345
6789101112
13141516171819
20212223242526
2728293031