wiki:IntroEnvironment
close Warning: Can't synchronize with repository "(default)" (/project/ucw/svn does not appear to be a Subversion repository.). Look in the Trac log for more information.

Configuration <- back | toc | forward -> Basic ucw mechanics

Setting up the environment (and a hello world on the side)

Note that this procedure is not strict necessary, you could just fiddle around in ucw-user, but you will want to have your own proper environment sooner or later. To get the best of both worlds (being lazy and having a proper set up environment), just download the code we're going to create below (mod_lisp users, check the www-dir stuff below for a correct setup). For the less lazy, create a directory where you want to keep your application code. (halfway ripped from the cliki tutorial. thanks ;-)).

Create an asdf file called ucw-intro.asd will contain:

(defpackage :ucw.intro.system
  (:use :cl :asdf))
    
(in-package :ucw.intro.system)
    
(defsystem ucw-intro
  :version "0.0.0.0.1"
  :depends-on (:ucw)
  :author "a lonely clown"
  :components ((:file "packages")
               (:file "config"      :depends-on ("packages"))
               (:file "hello-world" :depends-on ("config"))))
    

and a package file called packages.lisp:

(in-package :cl-user)
    
(defpackage :ucw-intro
  (:use :common-lisp
        :it.bese.ucw
        :it.bese.arnesi
        :it.bese.yaclml))
    

make a symlink from your asd file to the applications.d dir you defined in the last chapter.

Important: when ucw loads it checks this directory for .asd files of your ucw applications. To let them load correctly you have to synchronize four names in your applications with standard pre- and suffixes:

  • the name of your applications asd file: name.asd (in this case ucw-intro.asd)
  • the name of your applications package: :name (in this case :ucw-intro)
  • the name of your application: *name-application* (in this case *ucw-intro-application*, see below in the ucw-intro.lisp code)
  • the asdf system name of your package as defined with defsystem: :name (in this case :ucw-intro)

This procedure might be streamlined in the future, but for now we have to deal with it.

There is also an alternative way of loading your applications when loading ucw. In /etc/ucw/conf.lisp (or where-ever you decided to put the file), push the name of your applications asd system name on *ucw-systems* and push it's application name (see below in the ucw-intro.lisp code), on *ucw-applications* like it's done for the ucws example applications:

(defvar *ucw-systems* '(:ucw.admin :ucw.examples))
(defvar *ucw-applications* '(it.bese.ucw::*admin-application*
	    		         it.bese.ucw-user::*example-application*))
    

If you don't want them to load, take them away from both conf.lisp and /path/to/ucw_dev/src/default.lisp.

We also need a www root directory. This is the directory where we store static files for the http server to see: css and javascript files, pictures and the like. Lisp servers handle the www directory a bit different than mod_lisp so we have to make apt provisions. Lisp servers can themselves map a path from an incoming uri to the underlying directories on a server. When we use mod_lisp we have to tell apache as well as lisp where to go.

When you use a lisp server backend, just create a directory in the tutorial root and call it www if you want to be in sync with this tutorial. With mod_lisp make a link from a directory somewhere in the apache www tree and in range of the mod_lisp search path as explained in the installation section. With apache 2 a typical path would be /var/www/locahost/htdocs/. The apache 1 www root normally also lies somewhere within that vicinity.

ln -s /path/to/ucw-intro/www var/www/localhost/htdocs/ucw-intro
    

Or link the other way around.

Now we create two new file in our example application root called ucw-intro.lisp and config.lisp. config.lisp:

(in-package :ucw-intro)
    
(defvar *www-root*
  (merge-pathnames
   (make-pathname :directory '(:relative "www"))
   (asdf:component-pathname (asdf:find-system :ucw-intro))))
    
(defparameter *ucw-intro-application*
  (make-instance 'cookie-session-application
                 :url-prefix "/ucw-intro/"
                 :www-roots (list *www-root*)
                 :dispatchers (list (action-dispatcher)
                                    ;; hello world
                                    (url-dispatcher "hello-world.ucw"
                                      (call 'hello-world)))
                 :debug-on-error t))
    

hello-world.lisp:

(in-package :ucw-intro)
    
(defcomponent hello-world (simple-window-component) ()
              (:default-initargs :title "hi" :stylesheet "sheet.css"
              :stylesheet '("sheet.css" "sheet2.css")
              :content-type "text/html; charset=utf-8;"
              :javascript '((:src "dojo.js")
                            (:js (dojo.require "dojo.event.*"))
                            (:script "var foo = 3;")))
;;            (:entry-point "hello-world.ucw" (:application *ucw-intro-application* :class url-dispatcher))
              (:render () (<:as-html "hello world")))
    

Load the files into your image and register them with the server:

(ucw:register-application ucw:*default-server* ucw-intro::*ucw-intro-application*)

Now surf to http://127.0.0.1(:8080)/ucw-intro/hello-world.ucw, cross your fingers... and... now you've printed "hello world"! (If the heavens are willing).

Recently, because of code-change, you need to add beforementioned register-application form at the bottom of start.lisp, under (ucw:create-server), to get your application noticed at startup. But..,

As mentioned in the previous chapter, the ucwctl/applications.d mechanism will probably disappear. A simpler way to start ucw is to just load start.lisp in your lisp or directly through detachtty. You can change beforementioned variables (for example which backend to choose or on which port to listen) in /path/to/ucw/src/vars.lisp. To load and register your own applications, modify the relevant parts of start.lisp (in this case to load ucw-intro) to resemble:

;;;; Load up UCW itself plus the examples
(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op :ucw)
  (asdf:oos 'asdf:load-op :ucw.admin)
  (asdf:oos 'asdf:load-op :ucw.examples)
  (asdf:oos 'asdf:load-op :ucw-intro)
  #+(or (and sbcl sb-unicode) (and clisp unicode))
  (asdf:oos 'asdf:load-op :ucw.examples.l10n))

;;;; Tell UCW which apps to serve
(setf ucw.system:*ucw-applications* '(ucw-user::*example-application*
                                      #+(or (and sbcl sb-unicode) (and clisp unicode))
                                      ucw-user::*l10n-example-application*
                                      ucw::*admin-application*
                                      ucw-intro::*ucw-intro-application*))

Much easier eh!

In the next chapter we will see what applications actually are, and we will examine the contents of ucw-intro.lisp. Also we will discuss the mechanics of ucw. Actually the next chapter is the most important chapter of this intro. Finally the foreplay is over.

Configuration <- back | toc | forward -> Basic ucw mechanics

Last modified 18 years ago Last modified on 07/28/06 06:39:28