The Source for Java Technology Collaboration
User: Password:



Cay Horstmann

Cay Horstmann's Blog

Installing GlassFish and PostgreSQL on Ubuntu Server Edition

Posted by cayhorstmann on July 18, 2006 at 08:09 AM | Comments (7)

???I am getting ready for the fall semester. My software engineering students will be using GlassFish for their projects. In order to avoid the "but it worked on my computer" syndrome, I make them deploy their apps on a server in my office. I just installed Ubuntu Server Edition. These instructions got me started with the Linux basics. This blog has the (not so) gory details for installing Java, GlassFish, and PostgreSQL. At the end are the obligatory reflective comments.

I ran all these steps as super-user. Note that Ubuntu Server has no GUI interface by default. I simply put the in a corner, connected with ssh, and ran the commands in a terminal. Required skills: bash shell basics and a stone-age text editor such as vi.

Java

  1. Edit /etc/apt/sources.list, uncomment the lines for adding universe, and manually add multiverse at the end:
    deb http://us.archive.ubuntu.com/ubuntu/ dapper universe multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ dapper universe multiverse
  2. Run
    apt-get install sun-java5-jdk
  3. Run
    java -version
    You should get something like
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
    

Wow. That was phenomenally easy.

???GlassFish

  1. Go to and look for the version that you want to download.
  2. Download it with
    wget http://java.net/download/javaee5/promoted/Linux/glassfish-installer-v2-b09.jar
    but substitute the correct version number.
  3. Run
    java -jar -mx256M glassfish-installer-v2-b09.jar
    (Again, substitute the correct version number.) The installer automatically runs in headless mode, without a GUI.
  4. Move the installation somewhere permanent. I want to be able to get new versions as they become available without having to change many configuration files. I'll put this version into /opt/glassfish-v2-b09 and make a symlink /opt/glassfish.
    mv glassfish /opt/glassfish-v2-b09
    ln -s /opt/glassfish-v2-b09 /opt/glassfish
  5. Run setup.xml in the usual way:
    cd /opt/glassfish
    /opt/glassfish/lib/ant/bin/ant -f setup.xml
  6. I wanted the default domain to be in a separate directory so that I could install new versions. There must be a better way of controlling the domain directory, but for now I used a brute-force approach, again with symlinks.
    mv /opt/glassfish/domains/domain1 /opt
    ln -s /opt/domain1 /opt/glassfish/domains/domain1
  7. It seems prudent to change the admin password on a public server:
    /opt/glassfish/bin/asadmin change-admin-password --user admin
    Please enter the old admin password>adminadmin
    Please enter the new admin password>(password is echoed)
    Please enter the new admin password again>(password is echoed)
    The password needs to be at least 8 characters long.
    I then had to remove ~/.adminpass and run /opt/glassfish/bin/asadmin login to regenerate it, but that may have been a fluke.
  8. I want GlassFish to be a service that starts up automatically. There are probably better ways to do this, but here is my pedestrian approach. I produced a file /etc/init.d/glassfish with this content:
    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides:          glassfish
    # Required-Start:    $local_fs $remote_fs
    # Required-Stop:     $local_fs $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      S 0 1 6
    # Short-Description: glassfish initscript
    # Description:       A simple initscript for the glassfish app server
    ### END INIT INFO
    #
    # Author:            Cay S. Horstmann (http://horstmann.com)
    #
    
    set -e
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/glassfish/bin
    DESC="Java EE5 App Server"
    NAME=glassfish
    ASADMIN=asadmin
    PIDFILE=/var/run/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME
    
    # Gracefully exit if the package has been removed.
    test -x $DAEMON || exit 0
    
    # Read config file if it is present.
    #if [ -r /etc/default/$NAME ]
    #then
    #       . /etc/default/$NAME
    #fi
    
    #
    #       Function that starts the daemon/service.
    #
    d_start() {
            $ASADMIN start-domain \
                    || echo -n " already running"
    }
    
    #
    #       Function that stops the daemon/service.
    #
    d_stop() {
            $ASADMIN stop-domain \
                    || echo -n " not running"
    }
    
    case "$1" in
      start)
            echo -n "Starting $DESC: $NAME"
            d_start
            echo "."
            ;;
      stop)
            echo -n "Stopping $DESC: $NAME"
            d_stop
            echo "."
            ;;
      reload|restart|force-reload)
            echo -n "Restarting $DESC: $NAME"
            d_stop
            sleep 10
            d_start
            echo "."
            ;;
      *)
            echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
            exit 3
            ;;
    esac
    
    exit 0
    
    
    No, I don't know what I am doing. I just modified /etc/init.d/skeleton. Then I ran
    update-rc.d glassfish defaults
  9. At this point, you should be able to reboot the machine and point a browser to http://machinename:4848. The admin interface should come up.
    ???

PostgreSQL

  1. Run
    apt-get install postgresql-8.1 postgresql-client-8.1
  2. Change the password:
    su postgres
    psql
    ALTER USER postgres WITH PASSWORD 'secret';
    \q
    exit
  3. Go to http://jdbc.postgresql.org/download.html and pick the most recent driver. Download it as
    wget http://jdbc.postgresql.org/download/postgresql-8.2dev-503.jdbc3.jar
    (Change the version number...)
  4. Copy the driver into /opt/glassfish/domains/domain1/lib and restart the server. Use either asadmin in the usual way or, if you installed GlassFish as a service, simply invoke-rc.d glassfish restart.
  5. Set up a connection pool and a JDBC resource. You can do this through the admin interface or directly from the command line. I did the latter. Each of the two commands should be on a single line.
    /opt/glassfish/bin/asadmin create-jdbc-connection-pool 
       --datasourceclassname org.postgresql.ds.PGSimpleDataSource 
       --restype javax.sql.DataSource 
       --property portNumber=5432:password=secret:user=postgres:serverName=localhost:databaseName=postgres 
       PostgresPool
    /opt/glassfish/bin/asadmin create-jdbc-resource 
       --connectionpoolid PostgresPool 
       jdbc/Postgres
    
  6. ???Try it out. Download the Elvis quiz app.
    wget http://horstmann.com/elvis/quiz.zip
    mkdir quiz
    cd quiz
    jar xvf ../quiz.zip
    
    Edit build.properties and change the password. Edit conf/persistence.xml and specify the data source:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
        <persistence-unit name="defaultPersistenceUnit">
            <jta-data-source>jdbc/Postgres</jta-data-source>
            <properties>
                <property name="toplink.logging.level" value="FINEST"/>
            </properties>
        </persistence-unit>
    </persistence>
    Now run
    /opt/glassfish/lib/ant/bin/ant run-client
    You should get a message such as
    run-client:
         [java] elvis.entity.Quiz[id=26,title=A Java Trivia Quiz,questions={IndirectList: not instantiated}]
    

The Obligatory Reflective Comments

???First off, apt-get is great. This was far and away the easiest JDK installation I have ever done. I didn't have to fuss with the PATH. I'll get alerted when new versions appear and can update them easily. There is some behind-the-scenes work that makes Sun's Java the preferred one (rather than GCJ).

I'd love to be able to run apt-get install glassfish.

I never installed much software on a headless server before and I was pleasantly surprised how easy it was. But if that isn't your cup of tea, you can use the admin web interface to do most steps.

The Glassfish installer needs to do something about the service script. Maybe someone can contribute this? It is an open source project, after all.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first)

  • Nifty!This setup seems perfect for teaching the basics. Two questions:
    What hardware requirements do you give your students?Would it be possible to do one install, and clone the drive (or better yet copy an image on a USB drive)?Thanks!-JohnR

    Posted by: johnreynolds on July 18, 2006 at 08:18 AM

  • if you want to start packaging glassfish, join #debian-java on freenode, and read the debian packaging guidelines. If it works and builds with gcj/kaffe/cacao/any-other-free-runtime, it can go into debian's main archive, otherwise it goes into debian's contrib.

    cheers,
    dalibor topic

    Posted by: robilad on July 18, 2006 at 09:43 AM

  • ah, i mean irc.oftc.net ... the channel has moved last month. :)

    Posted by: robilad on July 18, 2006 at 09:45 AM

  • JohnR--most of my students will be running Windows and Derby on their own laptops, not Linux and PostgreSQL. I don't think that drive cloning or a USB stick would help them.

    Why have a server? Students submit their work into CVS on my server, and then a script builds their projects and deploys them.
    Without my server, they (a) wouldn't use version control and (b) would email me zip files with code that can't be built on any system but theirs.

    "You come in here with a skull full of mush and you leave thinking like a coder."

    Posted by: cayhorstmann on July 18, 2006 at 01:12 PM

  • Hi Cay
    Thank you for your great info on setting up class fish and the startup script. I have one question about installing a new build, i have created sym links, what i dont understand is how it works. When i unwrap another version this will give me the glassfish folder, where do i move that to so the links still work? seen as the real folder has name glassfish-v2-b17. I would be greatfull if you could enlighten me.
    Kind regards Chainy

    Posted by: chainy on September 19, 2006 at 04:31 PM

  • Hi Cay Thank you for your great info on setting up class fish and the startup script. I have one question about installing a new build, i have created sym links, what i dont understand is how it works. When i unwrap another version this will give me the glassfish folder, where do i move that to so the links still work? seen as the real folder has name glassfish-v2-b17. I would be greatfull if you could enlighten me. Kind regards Chainy

    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo


    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo
    sexo

    Posted by: agumik on November 09, 2006 at 02:01 AM

  • YUM Repository ?..
    Somebody knows any YUM repositories containing this package for Fedora 4 ?...

    thank you!... Eyaculacion Precoz Tratamiento


    Posted by: javigui on January 15, 2007 at 08:29 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds