Skip to content Skip to sidebar Skip to footer

How To Build An Openlaszlo Dhtml Application Using Apache Ant

I've read about OpenLaszlo's lzdeploy tool, but there seems to be only little documentation available. It should be possible to build an OpenLaszlo DHTML application using Apache A

Solution 1:

Here is a full Ant build script which you can use with OpenLaszlo 5.0 (haven't tested with older versions).

<?xml version="1.0" encoding="UTF-8"?><projectname="olApp"default="build"basedir="."><description>Ant Build Script for OpenLaszlo DHTML App</description><!-- OpenLaszlo canvas app filename --><propertyname="app.file"value="testapp.lzx" /><!-- LPS home folder --><propertyname="lps.home"value="PLEASE SET YOUR LPS_HOME FOLDER HERE!!!" /><!-- Build timestamp --><propertyname="build.timestamp"value="will be the set through script below" /><scriptlanguage="javascript">var date = newDate();
    var stamp = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss").format(date);
    olApp.setProperty("build.timestamp", stamp);
  </script><propertyname="project.folder"value="will be set through the script below" /><scriptlanguage="javascript">var lpsHome = olApp.getProperty("lps.home"),
    basedir = olApp.getProperty("basedir"),
    fileSep = java.lang.System.getProperty("file.separator"),
    projectFolder = "app";
    olApp.setProperty("project.folder", projectFolder)
  </script><!-- Default directories  --><propertyname="lzx.dir"location="${basedir}/lzx" /><propertyname="build.dir"location="${basedir}/build" /><propertyname="temp.dir"location="${build.dir}/tmp" /><propertyname="release.dir"location="${basedir}/release" /><!-- CLASSPATH for Laszlo compiler lzc --><pathid="laszlo.compiler.classpath"><pathelementlocation="${lps.home}/WEB-INF/lps/server/build"/><pathelementlocation="${lps.home}/WEB-INF/classes"/><filesetdir="${lps.home}/WEB-INF/lib"includes="**/*.jar"/></path><targetname="info"description="Dump useful configuration information before build"><echomessage="Using LPS in ${lps.home}" /><echomessage="Editor appl path relative to $LPS_HOME is  $LPS_HOME/${project.folder}" /><echomessage="Timestamp for this build is ${build.timestamp} "/></target><targetname="clean"depends="info"description="Delete all temporary and generated files and folders."><!-- If the application file has been compiled using the
         browser developer console, remove all generate files. --><scriptlanguage="javascript">var file = olApp.getProperty("app.file");
      olApp.setProperty("masterSpriteFile", 
      file.substr(0,file.indexOf(".lzx")) + ".sprite.png");
    </script><delete><filesetdir="${lzx.dir}"><includename="**/*.sprite.png"/><includename="**/*.swf10.swf"/><includename="**/*.lzx.js"/></fileset></delete><deletedir="${lzx.dir}/lps"/><deletefile="${lzx.dir}/${app.file}.js" /><deletefile="${lzx.dir}/${app.file}.swf10.swf" /><deletefile="${lzx.dir}/${masterSpriteFile}" /><echomessage="Property app.file set to ${app.file}" /><deletedir="${build.dir}" /><deletedir="${release.dir}" /></target><targetname="init"depends="clean"description="Create all directories for the build process."><mkdirdir="${temp.dir}" /><mkdirdir="${temp.dir}/lzxcompile" /><mkdirdir="${temp.dir}/lzdeploy" /><mkdirdir="${build.dir}" /><mkdirdir="${release.dir}" /></target><targetname="build"depends="init,compile-lzx"description="Compile Java and LZX source (SWF10 and DHTML), and copy the versions into the release folder."></target><!-- Copy LZX, JSP and other text files into folder ${temp.dir}.
       We don't want to pollute the source folder with files generated
       during compilation. --><targetname="copy-files-temp"depends="init"><echomessage="Copying files from ${lzx.dir} to ${temp.dir}/lzxcompile" /><copytodir="${temp.dir}/lzxcompile"><filesetdir="${lzx.dir}"casesensitive="no"><!-- Include any file type here you want to package into the
             deployed application. --><includename="**/*.lzx" /><includename="**/*.xml" /><includename="**/*.jsp" /><includename="**/*.html" /><includename="**/*.js" /><includename="**/*.css" /><includename="**/*.gif" /><includename="**/*.jpg" /><includename="**/*.mp3" /><includename="**/*.pdf" /><includename="**/*.png" /><includename="**/*.swf" /><includename="**/*.ttf" /></fileset></copy></target><!-- Compile the LZX code for both the DHTML and SWF10 runtime --><targetname="compile-lzx"depends="init,copy-files-temp" ><echomessage="Compiling LZX app for SWF10 and DHTML runtime (SOLO)"/><scriptlanguage="javascript">var lzxFile = olApp.getProperty("app.file");
      var timestamp = olApp.getProperty("build.timestamp");
      var fileNoending = lzxFile.substr(0,lzxFile.indexOf(".lzx"));
      olApp.setProperty("app.file.timestamp",
      fileNoending + "." + timestamp + ".lzx");
    </script><movefile="${temp.dir}/lzxcompile/${app.file}"tofile="${temp.dir}/lzxcompile/${app.file.timestamp}" /><!-- SWF10 with Laszlo Debugger enabled --><antcalltarget="_solo-compile-file"><paramname="file"value="${temp.dir}/lzxcompile/${app.file.timestamp}" /><paramname="runtime"value="swf10" /><paramname="debug"value="--debug"/><paramname="output"value="${temp.dir}/lzdeploy/swf10-debug.zip" /></antcall><antcalltarget="_unzip-lzdeploy-package"><paramname="output"value="${temp.dir}/lzdeploy/swf10-debug.zip" /><paramname="targetFolder"value="${temp.dir}/lzdeploy/swf10-debug" /></antcall><!-- FIX: lzdeploy bug workaround
         The SWF10 file is currently not added to the ZIP file, need to
         copy it over --><copyfile="${temp.dir}/lzxcompile/${app.file.timestamp}.swf10.swf"tofile="${temp.dir}/lzdeploy/swf10-debug/${app.file.timestamp}.swf10.swf" /><!-- DHTML with Laszlo Debugger enabled --><antcalltarget="_solo-compile-file" ><paramname="file"value="${temp.dir}/lzxcompile/${app.file.timestamp}" /><paramname="runtime"value="dhtml" /><paramname="debug"value="--debug"/><paramname="output"value="${temp.dir}/lzdeploy/dhtml-debug.zip" /></antcall><antcalltarget="_unzip-lzdeploy-package"><paramname="output"value="${temp.dir}/lzdeploy/dhtml-debug.zip" /><paramname="targetFolder"value="${temp.dir}/lzdeploy/dhtml-debug" /></antcall><!-- DHTML without Laszlo Debugger --><antcalltarget="_solo-compile-file" ><paramname="file"value="${temp.dir}/lzxcompile/${app.file.timestamp}" /><paramname="runtime"value="dhtml" /><paramname="output"value="${temp.dir}/lzdeploy/dhtml.zip" /></antcall><antcalltarget="_unzip-lzdeploy-package"><paramname="output"value="${temp.dir}/lzdeploy/dhtml.zip" /><paramname="targetFolder"value="${temp.dir}/lzdeploy/dhtml" /></antcall><!-- Copy the files for each app version - including dependencies - 
         into the release folder. --><copytodir="${release.dir}/swf10-debug"><filesetdir="${temp.dir}/lzdeploy/swf10-debug/"><includename="**/*.*" /></fileset></copy><copytodir="${release.dir}/dhtml"><filesetdir="${temp.dir}/lzdeploy/dhtml/"><excludename="${app.file.timestamp}.swf10.swf" /><includename="**/*.*" /></fileset></copy><copytodir="${release.dir}/dhtml-debug"><filesetdir="${temp.dir}/lzdeploy/dhtml-debug/"><excludename="${app.file.timestamp}.swf10.swf" /><includename="**/*.*" /></fileset></copy></target><!-- Compile the file and create the ZIP package with resources --><targetname="_solo-compile-file"><echomessage="Creating application package for ${file}"/><echomessage="Using LPS_HOME: ${lps.home}"/><echomessage="args: --runtime=${runtime}  ${debug} --output ${output}"/><javaclasspathref="laszlo.compiler.classpath"classname="org.openlaszlo.utils.DeployMain"fork="yes"failonerror="true"><jvmargvalue="-Xmx1024M"/><jvmargvalue="-DLPS_HOME=${lps.home}"/><argline="--runtime=${runtime} --output ${output} ${debug} ${file}"/></java></target><!-- Unzip the OpenLaszlo deployment ZIP file --><targetname="_unzip-lzdeploy-package"><echomessage="Unzipping lzdeploy package ${output}" /><!--unzip src="${zip.target.file}" dest="${temp.zip.extracted}"--><unzipsrc="${output}"dest="${targetFolder}"><patternset><excludename="widget-icon.png" /><excludename="config.xml" /><!-- exclude name="index.html" /--><excludename="**/*.lzx" /><excludename="**/*.css" /></patternset></unzip></target></project>

Put the build script into a subfolder of $LPS_HOME (OpenLaszlo server home) called testapp. Create a subdirectory LZX, with an OpenLaszlo canvas application called testapp.lzx. I've added an image resource into the subfolder resources to test if resources are packaged correctly into the SOLO compiled application folders.

$LPS_HOME
└── testapp
    ├── build.xml
    └── lzx
        ├── resources
        │   └── Winnie-the-Pooh.jpg
        └── testapp.lzx

Got into $LPS_HOME, and run "ant build". The build process should run through, and you should have the resulting folder structure:

testapp
├── build
│   └── tmp
│       ├── lzdeploy (more files)
│       └── lzxcompile (more files)
├── build.xml
├── lzx
│   ├── resources
│   │   └── Winnie-the-Pooh.jpg
│   └── testapp.lzx
└── release
    ├── dhtml
    │   ├── index.html
    │   ├── lps (more files)
    │   ├── resources
    │   │   └── Winnie-the-Pooh.jpg
    │   ├── testapp.20120810-125652.lzx.js
    │   └── testapp.20120810-125652.sprite.png
    ├── dhtml-debug
    │   ├── index.html
    │   ├── lps (more files)
    │   ├── resources
    │   │   └── Winnie-the-Pooh.jpg
    │   ├── testapp.20120810-125652.lzx.js
    │   └── testapp.20120810-125652.sprite.png
    └── swf10-debug
        ├── index.html
        └── lps (more files)

The build process has generated three versions of the OpenLaszlo app: SWF with debug, DHTML/HTML5 with and without debug mode enabled. All JavaScript and SWF files have a timestamp attached, which means a new version of the application will not be pulled from the browser cache. If point your browser to the release folder, clicking on any of the three folders (swf10-debug, dhtml, dhtml-debug) should open the SOLO compiled app.

Add your own scripts to upload the release to a webserver, that should not be difficult.

Post a Comment for "How To Build An Openlaszlo Dhtml Application Using Apache Ant"