Introducing OpenLaszlo
by Sreekumar Parameswaran Pillai
|
Pages: 1, 2, 3, 4, 5
Configuring Ant To Deploy Laszlo and Web Applications
-
We'll create two files for this purpose: one build.xml that is the Ant script file, and the supplementary build.properties file that holds variables for configuration control.
-
Copy the following build.xml to the root folder of the web project.
Listing 4. build.xml
<!-- Master build-script for Laszlo tutorial Application. @author: Sreekumar.pillai@hotmail.com -->
<project name="laszlotutorial" default="compile" basedir=".">
<property file="build.properties" />
<!--classpath for ant -->
<path id="classpath">
<fileset dir="${tomcat-home}/server/lib" includes="*.jar" />
<fileset dir="${tomcat-home}/common/lib" includes="*.jar" />
</path>
<!-- Create a time stamp. -->
<target name="timestamp">
<tstamp>
<format property="build.time" pattern="MMMM d, yyyy hh:mm:ss z" />
</tstamp>
<echo message="Beginning build: ${build.time}" />
<echo message="Web app source: ${webapp.src}" />
<echo message="Java home: ${java.home}" />
<echo message="Java version: ${ant.java.version}" />
<echo message="Ant version: ${ant.version}" />
</target>
<!-- Initialization creates the dist and deploys directories. -->
<target name="init">
<mkdir dir="${classes.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${laszlo.deploy.dir}" />
</target>
<!-- Compile all source files to the classes folder. -->
<target name="compile">
<echo message="Compiling the java source files" />
<javac destdir="${build.dir}/classes" debug="on" optimize="on">
<src path="${java.base}" />
<classpath>
<path refid="classpath" />
<pathelement location="" />
</classpath>
</javac>
</target>
<!-- Deploys the Laszlo project to the Laszlo Presentation Server. -->
<target name="deploy-laszlo" depends="init">
<!-- Make an application folder in the project folder -->
<echo message="Deploying to Laszlo application to lps 3.2" />
<copy todir="${laszlo.deploy.dir}" overwrite="true" >
<fileset dir="${laszlo.basedir}/src" />
</copy>
</target>
<!-- Deploys the web application on the default Tomcat server. -->
<target name="deploy-web" depends="war">
<echo message="Deploying the web application to the tomcat server" />
<copy todir="${tomcat.webapps}" overwrite="true">
<fileset file="${dist.dir}/${war.name}.war" />
</copy>
<unwar overwrite="true" src="/2006/10/11/graphics/${tomcat.webapps}/${war.name}.war" dest="${tomcat.webapps}/${war.name}" />
</target>
<!-- Deploys both web and Laszlo applications. -->
<target name="deploy-all" depends="deploy-laszlo,deploy-web">
</target>
<!-- Archives java class files into laszlojava.jar file. -->
<target name="jar" depends="compile">
<echo message="Archiving the java classes into .jar" />
<jar basedir="${classes.dir}" file="${webinf}/lib/${java.project.name}.jar" />
</target>
<!-- Creates the laszlotutorial.war. -->
<target name="war" depends="jar">
<echo message="Generating the .war file" />
<!-- Create the .war file for deployment. -->
<war basedir="${webapp.src}" manifest="${webapp.src}/META-INF/MANIFEST.MF" warfile="${dist.dir}/${war.name}.war" webxml="${webinf}/web.xml">
</war>
</target>
</project>
-
The build.properties should also go along with the build.xml to the root folder of the web project.
Listing 5. build.properties
# Base directories
laszlo.basedir=C:/laszlosetup/laszlotutorial
laszlo.src=${laszlo.basedir}/src
# Web Application folders
webapp.basedir= C:/laszlosetup/laszloweb
# Web application properties
war.name=laszlotutorial
webapp.src=${webapp.basedir}/WebContent
webinf=${webapp.src}/WEB-INF
build.dir=${webapp.basedir}/build
dist.dir=${webapp.basedir}/dist
classes.dir=${build.dir}/classes
javac.debug=true
junit.fork=true
compile.deprecation=true
# name of the laszlo application
laszloapp.name=laszlotutorial.
# 2 Java application properties
java.base=${webapp.basedir}/src
java.project.name=laszlojava
# deployment directories
laszlo.deploy.dir=C:/Tools/OpenLaszlo Server 3.2/Server/lps-3.2/laszlotutorial
tomcat.webapps=C:/Tools/OpenLaszlo Server 3.2/Server/tomcat-5.0.24/webapps
tomcat-home=C:/Tools/OpenLaszlo Server 3.2/Server/tomcat-5.0.24
Enable the Ant View of build.xml:
-
Go to window >> Show View >> Other... and in the Show View, select Ant.

Figure 15. build.xml in the Ant view
-
In the Ant view, click the "Add Build files" (the button with the ant icon) and select the build.xml file.
-
The Ant view should now display the ant targets in the build.xml file.

Figure 16. Targets in build.xml
Deploy the Applications
-
Double-click the deploy-all target, and both Laszlo and the web application are deployed to their locations on the respective servers.

Figure 17. The console after running the deploy-all target (Click image for full-size.)
-
Open a browser instance and enter the following URL: http://localhost:8080/lps-3.2/laszlotutorial/helloworld.lzx. The window should be displayed with the message from the server.

Figure 18. The "Hello World from the Server!!" in the browser
Runtime Compilation
The Laszlo Presentation Server has an inbuilt caching mechanism to speed up delivery of compiled code to the client. When the server is started, the cache is rebuilt. During the development phase, the server seldom needs to be restarted since the default setting is for changed files to be recached.
In the current setup we have built, only a refresh is required for the changes to be reflected in the browser. Restarting the server is necessary only when there is a change in the configuration files. As such, the whole process of deploying and refreshing the view for a typical .lzx file should not take more than three seconds unless slowed down because of data fetching from the application layer.
Conclusion
Setting up the development environment could be a daunting task, especially when the technology is new. This article has focused primarily on using open source tools to set up a platform for developing a Laszlo/Java web application. I am sure this tutorial can help readers to a quick start with Laszlo development.
- OpenLaszlo Legal is the power to serve
2006-11-11 00:44:14 Arab - Design View / IDE4Laszlo for Java 1.5
2006-11-02 06:46:29 oscuro - Very good Article
2006-10-23 04:13:26 paulbrowne