Table of Contents
In this tutorial we will develop a sample shop web application to demonstrate the basic techniques that are needed to develop a Pustefix application. As this tutorial focuses on Pustefix, the backend / business logic code used in the examples will be as minimal as possible and just provide the functions absolutely needed by the frontend. This means the shop will not be a real world example in the sense that it will not work completely, however if you replace the backend with a full implementation, it should work, as the frontend part is designed like it was a real world application.
The author assumes that you are using the Eclipse IDE, however you can of course work with another IDE, although some of the methods described in this document might be slightly different.
Table of Contents
Before we can get started, you have to make sure that some requirements are met by your development environment. You will need:
The installation of these tools (except Tomcat) is not covered by this tutorial. Please refer to the documentation provided with these tools for installation instructions.
If you are not using Eclipse, you can just create an empty directory that will contain the project files and proceed with Section 2.3, “Unpack the skeleton”.
Start the Eclipse workbench and create a new project of type Java Project".
Make sure that you choose separate source and build folders: Use
src for the source and build for
the build folder. This is important because the Pustefix build script
expects these folders.
Download the newest pfixcore-skel-X.X.X.tar.gz from
Pustefix's downloads page.
Unpack the archive to a temporary directory. A new directory with the name
skel will be created. Copy the content of this directory
to your new project directory.
Now you need to download Apache Tomcat. Choose the
.tar.gz archive from the download page and place it in
the lib/tomcat directory of your project directory.
After you are done with that, refresh the resources view in Eclipse to make the new files appear.
To make features like auto-completion and auto-build work, you have to
import the libraries into Eclipse. Right-click on your project in Eclipse
and choose "Build Path" ⇒ "Configure Build Path...". Now use the
"Add JARs..." button to add all libraries from the project's
lib directory.
As Pustefix generates some classes, you have to add the folder with the
generated sources to Eclipse's source path. To make this work choose the
"Source" tab in the same dialog you used to configure the build path and
add the gensrc folder to the list of source folders.
Finally, you have to configure the path to the JAR file containing Ant.
In Eclipse choose "Window" ⇒ "Preferences". In the dialog window
choose "Java" ⇒ "Build Path" ⇒ "Classpath Variables". Choose
"New..." and create a variable with the name PFX_ANT_LIB
that contains the path to the lib/ant.jar within your
Ant installation directory.
Within the project directory, create a file called
build.properties containing two properties:
standalone.tomcat=true
makemode=test
The first property tells the build process, that we do want to run Tomcat without Apache Httpd integration. Apache Httpd integration can be useful, because static files can be served faster. However this is an advanced topic and for our purposes Tomcat alone will be okay.
The second parameter set the so-called "make mode". This flag can be
set to either "test" or "prod" and will cause the editor console
to appear in web pages when in "test" mode. In fact you can even make
your own settings depend on the make mode, but we will take care of
this later. For the moment "test" mode is just what we want. By the way,
whenever you switch the make mode, you should do a complete rebuild
using ant realclean && ant to make sure,
all resources have been built using the same make mode.
Now run ant to perform a first build of the
environment. This will create needed symlinks and initialize the
environment.
After all this stuff has be done, we can start with the interesting thing: Creating our first Pustefix application.
The skeleton environment contains a new project wizard that helps you
start a new project. Run the newproject.sh shell script
in the root of your project directory (input is emphasized).
************************************************** * * * Pustefix ProjectGenerator 1.0 * * * ************************************************** Please follow the instructions to create a new project. You can abort the process by pressing Ctrl + C. Please type in the projects name e.g. "myproject" techshop Please type in the projects default language (it's english if you leave the field blank). <= Leave it blank Please type in a comment for the Project It will be "projectname + comment" if you leave it blank. Tutorial TechShop Please type in a name for the servlet 1 shop Would you like to create another servlet? [yes] [no] no
Now run ant to build the new project. You can start the
Tomcat server using the startTomcat.sh script in the root
of the project environment. After Tomcat reports that it is ready, you
can point your browser to http://techshop.yourhost:8080/.
If you do not have a wildcard DNS record for your host, you might have
to create a record in /etc/hosts pointing to your IP.
Congratulations! You just created your first running Pustefix web application. At the moment it is quite simple, but we will change this during the next chapters of course.