TOTD #85: Getting Started with Django Applications on GlassFish v3
By arungupta on Jun 17, 2009
GlassFish v3 provides support for Dynamic Languages and Web Frameworks such as Ruby-on-Rails, Groovy/Grails, and Python/Django using this extensibility. This blog has published multiple tips on using Ruby-on-Rails at rubyonrails+totd and a few tips on Groovy/Grails at grails+totd. This blog will explain how to get started with deploying Python/Django applications on GlassFish v3 Preview. The blog will use Jython interpreter which is the Java implemention of Python.
Vivek already blogged about the detailed instructions and this blog shows how to run the pre-bundled samples.
- Download GlassFish v3 Preview.
- Install Jython 2.5
- Download Jython 2.5 from here.
- Install as:
java -jar ~/Downloads/jython_installer-2.5.0.jar
Choose the default options (pick your directory) as shown below:
and click on "Next" to start the installation process.
- As mentioned in Django
on Jython wiki, create the following aliases:
alias django-admin-jy="jython25 ~/tools/jython2.5.0/bin/django-admin.py"
- Invoking the command "jython25" from the installation
directory shows the Jython interpreter as:
Jython 2.5rc4 (Release_2_5rc4:6470, Jun 8 2009, 13:23:16)
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_13
Type "help", "copyright", "credits" or "license" for more information.
- Install Django
- Download Django 1.0.2 from here.
- Install Django 1.0.2 as:
~/tools >tar xzvf ~/Downloads/Django-1.0.2-final.tar.gz
. . .
~/tools/Django-1.0.2-final >jython25 setup.py install
. . .
- Install Jython container for GlassFish
- Start GlassFish
v3 Preview Update Center using the following command:
to see the screen as:
- Select "GlassFish v3 Jython Container" and click on "Install", "Accept" the license and complete the installation. Close the Update Center window. This installs Jython Container OSGi module and Grizzly Adapter JARs in the "glassfish/modules" directory.
- Start and configure GlassFish
- Start GlassFish as:
~/tools/glassfish/v3/preview/glassfishv3/glassfish >./bin/asadmin start-domain
- Configure Jython in GlassFish as:
~/tools/glassfish/v3/preview/glassfishv3/glassfish >./bin/asadmin create-jvm-options -Djython.home=/Users/arungupta/tools/jython2.5.0
created 1 option(s)
Command create-jvm-options executed successfully.
Make sure to specify the directory where Jython is installed.
- Deploy the samples bundled with the Django installation as:
~/tools/Django-1.0.2-final/examples >~/tools/glassfish/v3/preview/glassfishv3/glassfish/bin/asadmin deploy .
Command deploy executed successfully.
and now they are accessible at "http://localhost:8080/examples/" and shown as:
Make sure to specify the end "/" otherwise the context root is not resolved correctly and none of the links will work.
Click on "Hello World (HTML)" to see the output as:
And click on "Displaying request metadata" to see output as:
The same sample can, of course, run using the built-in development server as:
~/tools/Django-1.0.2-final/examples >jython25 manage.py runserver
0 errors found
Django version 1.0.2 final, using settings 'examples.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
and then accessible at "http://localhost:8000" as:
If you are using GlassFish v2 then Django applications can be deployed as a WAR file as explained here.
Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive of all the tips is available here.
Technorati: totd glassfish v3 django python