Creating an empty ztemplates web-application#

  • Download and install JDK 1.5 or later.
  • Download and install Apache Tomcat 6 (or some other web-container Servlet spec 2.5 or later)
  • Download ztemplates-x.x.x-bin.zip
  • Extract ztemplates-x.x.x-bin.zip
  • the extracted directory will be referred as ztemplates in the tutorial
  • create a directory called tutorial in the tomcat webapps directory
  • create the directories tutorial/WEB-INF tutorial/WEB-INF/classes
  • copy the jar files from ztemplates/samples/tutorial/WEB-INF/lib to tutorial/WEB-INF/lib
  • rename ztemplates-x.x.x.jar to ztemplates.jar (not a must in real world, just makes the example compiler calls work)
  • create a file called web.xml in WEB-INF. This setup enables both JSP and Velocity and installs ztemplates-web as a filter.


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	version="2.4">

<!--  
uncomment to provide a filter implementation 
to optimize application startup time 
-->
<!--
      	Restrict classpath scan to jars/classes known to contain ztemplates-relevant classes.
      	Best YourClassPathFilter extends ZDefaultClassPathFilter
-->
<!--
    <context-param>
      <param-name>ZIClassPathFilter</param-name>
      <param-value>com.yourcompany.YourClassPathFilter</param-value>
    </context-param>
-->

	<filter>
		<filter-name>ZTemplatesFilter</filter-name>
		<filter-class>
			org.ztemplates.web.ZTemplatesFilter
		</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>ZTemplatesFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>ERROR</dispatcher>
	</filter-mapping>

	<welcome-file-list>
		<welcome-file>/</welcome-file>
	</welcome-file-list>

	<jsp-config>
		<jsp-property-group>
			<display-name>JSPs</display-name>
			<url-pattern>*.jsp</url-pattern>
			<el-ignored>false</el-ignored>
			<scripting-invalid>false</scripting-invalid>
			<is-xml>false</is-xml>
		</jsp-property-group>
	</jsp-config>

	<listener>
		<listener-class>
			org.ztemplates.web.ZTemplatesContextListener
		</listener-class>
	</listener>

<!-- uncomment to add velocity support -->
  <listener>
    <listener-class>
	org.ztemplates.web.velocity.ZVelocityContextListener
  </listener-class>
</listener>

<!-- uncomment to add FreeMarker support -->
  <listener>
    <listener-class>
	org.ztemplates.web.freemarker.ZFreeMarkerContextListener
  </listener-class>
</listener>

</web-app>

  • create a file velocity.properties in WEB-INF
directive.foreach.counter.initial.value=0
resource.loader = classpath,file
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.cache=false
file.resource.loader.path=templates
classpath.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
classpath.resource.loader.cache=false
velocimacro.library=macro.vm
velocimacro.library.autoreload=true
  • create a file log4j.properties in WEB-INF/classes
log4j.rootCategory = debug, stdout
log4j.category.org.ztemplates.url.parser=info
log4j.category.org.ztemplates.classpath=info
# *** Output auf console *********************************
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c{1}:%L] - %m%n


I just followed these instructions. I needed to add a file called macro.vm at the root of my classpath to get this to work. I added and empty file and that fixed it. I don't think that was mentioned in the instructions anywhere. Other than that, ztemplates seems simple and productive. Thanks!

--Wayne Rasmuss, 09-Mar-2014 22:34

Neuen Anhang hinzuf�gen

Du bist nicht autorisiert, Anh�nge zu dieser Seite hochzuladen.
« Diese Seite (Version-) wurde zuletzt am 09-Mrz-2014 22:34 von Wayne Rasmuss ge�ndert.