Brief introduction
The Apache wicket is a powerful, component-based, lightweight Web application framework that separates presentation and business logic well. You can use it to create High-quality Web 2.0 applications that are easy to test, debug, and support. Assuming that other teams deliver an wicket based application, you must extend the application without modifying their code, or you will have to deliver a modular Web application that makes it easy for other teams to expand and customize. This article describes how to resolve this problem without introducing extra source code, markup, and configuration. We use Maven-war-plugin to combine projects, dynamically load Web pages with wicketstuff-annotations, and use the spring framework as a control inversion (IoC) container to achieve that goal, with the help of wicket- Spring-annot projects and MAVEN-dependent tweaks enhance the application.
This article is designed to show how to design and build a highly modular, scalable, wicket Web application from scratch. The article guides the reader through all the steps of the process, starting with the original Maven pom file, selecting the necessary dependencies until the configuration of the component, the automatic assembly of the Service (Autowire), and the loading of the Web page are completed.
This article includes two examples of MAVEN management applications--warsaw and global. Warsaw is a fully-configured Web application with two simple Web pages. Global relies on the Warsaw project, introduces a service and several new Web pages, and modifies the copy of the Warsaw component. These two Web applications are packaged as war files and configured to run in jetty or other servlet containers. You can easily start both applications by running the MVN jetty:run-war command at the command line.
Case
Suppose a Web application is built based on the wicket application framework, and you need to create a customized version of the existing application. For example, you need to add a link to the page header to link to an external resource. To implement this feature, you can create a new wicket panel component and add its instance to the page you want. If this is the ability to apply a major version, it's easy. But if you're not allowed to introduce any changes in functionality, you can only access the source code and resources of existing applications, how do you accomplish this? There are several ways to solve this problem. This article will be followed by an in-depth discussion of one of them.
MAVEN's War Plug-in
A simple Web application written in Java can be published as a war file containing compiled classes, JSP and XML files, static Web pages, and other resources. Use the Maven-war-plugin plug-in to complete the merging of several war files. All we need to do is set the package attribute for the war file in the applied Pom.xml file and set the dependency on the other war file. This article uses two sample applications-the main application Warsaw and the global that relies on the Warsaw project. Listing 1 and Listing 2 show the basic versions of Pom.xml in the Warsaw Project and the global project, respectively.
List 1:warsaw The base version of the Maven Pom.xml file in the project.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.modular</groupId>
<artifactId>warsaw</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Modular Wicket Warsaw Project</name>
<dependencies>
<!-- Warsaw项目的依赖配置 -->
</dependencies>
</project>