Packing Code"

From Documentation
m
m (remove empty version history (via JWB))
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
There are two ways to pack the customization code: part of Web application, or an independent JAR file.
+
__TOC__
 +
 
 +
There are two ways to pack the customization code: part of the Web application, or an independent JAR file. Packing as part of the Web application is straightforward. All you have to do is to specify the customization in <code>WEB-INF/zk.xml</code> as described in [[ZK Configuration Reference]].
 +
 
 +
In many cases, it is better to pack the customization code as an independent JAR file, such that it can be managed separately and reused in multiple Web applications.
 +
 
 +
=Where to Configure a JAR File=
 +
 
 +
The configuration of a JAR file can be placed in a file called <code>config.xml</code>, and it must be placed under <code>/metainfo/zk</code>. If the JAR file also provides the component definitions, you have to prepare another file called <code>lang-addon.xml</code> under the same directory<ref>For more information, please refer to [[ZK Client-side Reference/Language Definition|ZK Client-side Reference: Language Definition]].</ref>.
 +
 
 +
The content of <code>/metainfo/zk/config.xml</code> is similar to <code>WEB-INF/zk.xml</code>, except only a subset of configurations is allowed. Here is a sample (zkex.jar 's config.xml)<ref>For more information, please refer to [[ZK Configuration Reference/JAR File's config.xml|ZK Configuration Reference: JAR File's config.xml]].</ref>:
 +
 
 +
<source lang="xml">
 +
<config>
 +
<config-name>zkex</config-name><!-- used to resolve dependency -->
 +
<depends>zk</depends>
 +
 
 +
<version>
 +
<version-class>org.zkoss.zkex.Version</version-class>
 +
<version-uid>5.0.6</version-uid>
 +
<zk-version>5.0.0</zk-version><!-- or later -->
 +
</version>
 +
 
 +
<listener>
 +
<listener-class>org.zkoss.zkex.init.WebAppInit</listener-class>
 +
</listener>
 +
 
 +
<library-property>
 +
<name>org.zkoss.zul.chart.engine.class</name>
 +
<value>org.zkoss.zkex.zul.impl.JFreeChartEngine</value>
 +
</library-property>
 +
<library-property>
 +
<name>org.zkoss.zul.captcha.engine.class</name>
 +
<value>org.zkoss.zkex.zul.impl.JHLabsCaptchaEngine</value>
 +
</library-property>
 +
</config>
 +
</source>
 +
 
 +
<blockquote>
 +
----
 +
<references/>
 +
</blockquote>
 +
 
 +
=How to Initialize a JAR File=
 +
 
 +
Sometimes you have to initialize a JAR file. It can be done by implementing <javadoc type="interface">org.zkoss.zk.ui.util.WebAppInit</javadoc>, and then specifying it as a listener in <code>/metainfo/zk/config.xml</code>. For example,
 +
 
 +
<source lang="java">
 +
public class MyJARInit implements WebAppInit {
 +
    public void init(WebApp wapp) throws Exception {
 +
        //do whatever init you need
 +
    }
 +
}
 +
</source>
 +
 
 +
Notice that many configurations can be done by accessing <javadoc>org.zkoss.zk.ui.util.Configuration</javadoc> directly. If you want to access it in <javadoc method="init(org.zkoss.zk.ui.WebApp)" type="interface">org.zkoss.zk.ui.util.WebAppInit</javadoc>, invoke <javadoc method="getConfiguration()">org.zkoss.zk.ui.WebApp</javadoc> as follows.
 +
 
 +
<source lang="java">
 +
    public void init(WebApp wapp) throws Exception {
 +
        Configuration config = wapp.getConfiguration();
 +
...
 +
</source>
 +
 
  
=Version History=
 
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 04:33, 5 February 2024

There are two ways to pack the customization code: part of the Web application, or an independent JAR file. Packing as part of the Web application is straightforward. All you have to do is to specify the customization in WEB-INF/zk.xml as described in ZK Configuration Reference.

In many cases, it is better to pack the customization code as an independent JAR file, such that it can be managed separately and reused in multiple Web applications.

Where to Configure a JAR File

The configuration of a JAR file can be placed in a file called config.xml, and it must be placed under /metainfo/zk. If the JAR file also provides the component definitions, you have to prepare another file called lang-addon.xml under the same directory[1].

The content of /metainfo/zk/config.xml is similar to WEB-INF/zk.xml, except only a subset of configurations is allowed. Here is a sample (zkex.jar 's config.xml)[2]:

<config>
	<config-name>zkex</config-name><!-- used to resolve dependency -->
	<depends>zk</depends>

	<version>
		<version-class>org.zkoss.zkex.Version</version-class>
		<version-uid>5.0.6</version-uid>
		<zk-version>5.0.0</zk-version><!-- or later -->
	</version>

	<listener>
		<listener-class>org.zkoss.zkex.init.WebAppInit</listener-class>
	</listener>

	<library-property>
		<name>org.zkoss.zul.chart.engine.class</name>
		<value>org.zkoss.zkex.zul.impl.JFreeChartEngine</value>
	</library-property>
	<library-property>
		<name>org.zkoss.zul.captcha.engine.class</name>
		<value>org.zkoss.zkex.zul.impl.JHLabsCaptchaEngine</value>
	</library-property>
</config>

  1. For more information, please refer to ZK Client-side Reference: Language Definition.
  2. For more information, please refer to ZK Configuration Reference: JAR File's config.xml.

How to Initialize a JAR File

Sometimes you have to initialize a JAR file. It can be done by implementing WebAppInit, and then specifying it as a listener in /metainfo/zk/config.xml. For example,

public class MyJARInit implements WebAppInit {
    public void init(WebApp wapp) throws Exception {
        //do whatever init you need
    }
}

Notice that many configurations can be done by accessing Configuration directly. If you want to access it in WebAppInit.init(WebApp), invoke WebApp.getConfiguration() as follows.

    public void init(WebApp wapp) throws Exception {
        Configuration config = wapp.getConfiguration();
...




Last Update : 2024/02/05

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.