Appendix A: Working with Maven

A.1. Switching Wicket to DEPLOYMENT mode

As pointed out in the note in paragraph 4.2, Wicket can be started in two modes, DEVELOPMENT and DEPLOYMENT. When we are in DEVELOPMENT mode Wicket warns us at application startup with the following message:

  1. ********************************************************************
  2. *** WARNING: Wicket is running in DEVELOPMENT mode. ***
  3. *** ^^^^^^^^^^^ ***
  4. *** Do NOT deploy to your live server(s) without changing this. ***
  5. *** See Application#getConfigurationType() for more information. ***
  6. ********************************************************************

As we can read Wicket itself discourages us from using DEVELOPMENT mode into production environment. The running mode of our application can be configured in four different ways. The first one is adding a filter parameter inside deployment descriptor web.xml:

  1. <filter>
  2. <filter-name>wicket.MyApp</filter-name>
  3. <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
  4. <init-param>
  5. <param-name>applicationClassName</param-name>
  6. <param-value>org.wicketTutorial.WicketApplication</param-value>
  7. </init-param>
  8. <init-param>
  9. <param-name>configuration</param-name>
  10. <param-value>deployment</param-value>
  11. </init-param>
  12. </filter>

The additional parameter is named configuration. The same parameter can be also expressed as context parameter:

  1. <context-param>
  2. <param-name>configuration</param-name>
  3. <param-value>deployment</param-value>
  4. </context-param>

The third way to set the running mode is using system property wicket.configuration. This parameter can be specified in the command line that starts up the server:

  1. java -Dwicket.configuration=deployment ...

The last option is to set it in your Java code (e.g. in the init-method of your WebApplication):

  1. setConfigurationType(RuntimeConfigurationType.DEPLOYMENT);

Remember that system properties overwrite other settings, so they are ideal to ensure that on production machine the running mode will be always set to DEPLOYMENT.

A.2. Creating a Wicket project from scratch and importing it into our favourite IDE

In order to follow the instructions of this paragraph you must have Maven installed on your system. The installation of Maven is out of the scope of this guide but you can easily find an extensive documentation about it on Internet. Another requirement is a good Internet connection (a flat ADSL is enough) because Maven needs to connect to its central repository to download the required dependencies.

A.2.1. From Maven to our IDE

Wicket project and its dependencies are managed using Maven. This tool is very useful also when we want to create a new project based on Wicket from scratch. With a couple of shell commands we can generate a new project properly configured and ready to be imported into our favourite IDE. The main step to create such a project is to run the command which generates project’s structure and its artifacts. If we are not familiar with Maven or we simply don’t want to type this command by hand, we can use the utility form on Wicket site at http://wicket.apache.org/start/quickstart.html :

quickstart webpage

Here we have to specify the root package of our project (GroupId), the project name (ArtifactId) and which version of Wicket we want to use (Version). Once we have run the resulting command in the OS shell, we will have a new folder with the same name of the project (i.e the ArtifactId). Inside this folder we can find a file called pom.xml. This is the main file used by Maven to manage our project. For example, using “org.wicketTutorial” as GroupId and “MyProject” as ArtifactId, we would obtain the following artifacts:

  1. .\MyProject
  2. | pom.xml
  3. |
  4. \---src
  5. +---main
  6. | +---java
  7. | | \---org
  8. | | \---wicketTutorial
  9. | | HomePage.html
  10. | | HomePage.java
  11. | | WicketApplication.java
  12. | |
  13. | +---resources
  14. | | log4j.properties
  15. | |
  16. | \---webapp
  17. | \---WEB-INF
  18. | web.xml
  19. |
  20. \---test
  21. \---java
  22. \---org
  23. \---wicketTutorial
  24. TestHomePage.java

Amongst other things, file pom.xml contains a section delimited by tag which declares the dependencies of our project. By default the Maven archetype will add the following Wicket modules as dependencies:

  1. ...
  2. <dependencies>
  3. <!-- WICKET DEPENDENCIES -->
  4. <dependency>
  5. <groupId>org.apache.wicket</groupId>
  6. <artifactId>wicket-core</artifactId>
  7. <version>${wicket.version}</version>
  8. </dependency>
  9. <dependency>
  10. <groupId>org.apache.wicket</groupId>
  11. <artifactId>wicket-ioc</artifactId>
  12. <version>${wicket.version}</version>
  13. </dependency>
  14. <!-- OPTIONAL DEPENDENCY
  15. <dependency>
  16. <groupId>org.apache.wicket</groupId>
  17. <artifactId>wicket-extensions</artifactId>
  18. <version>${wicket.version}</version>
  19. </dependency>
  20. -->
  21. ...
  22. </dependencies>
  23. ...

If we need to use more Wicket modules or additional libraries, we can add the appropriate XML fragments here.

A.2.2. Importing a Maven project into our IDE

Maven projects can be easily imported into the most popular Java IDEs. However, the procedure needed to do this differs from IDE to IDE. In this paragraph we can find the instructions to import Maven projects into three of the most popular IDEs among Java developers: NetBeans, JetBrains IDEA and Eclipse.

NetBeans Starting from version 6.7, NetBeans includes Maven support, hence we can start it and directly open the folder containing our project:

netbeans maven import

Intellj IDEA Intellj IDEA comes with a Maven importing functionality that can be started under “File/New Project/Import from external model/Maven”. Then, we just have to select the pom.xml file of our project:

intellj maven import

Eclipse Just like the other IDEs Eclipse supports Maven projects out of the box. Open the “File/Import…​” dialog and search for Maven:

eclipse maven import

then, select the project folder containing the POM file:

eclipse maven select

Once the project has been imported into Eclipse, we are free to use our favourite plug-ins to run it or debug it (like for example run-jetty-run).

A.2.3. Speeding up development with plugins.

Now that we have our project loaded into our IDE we could start coding our components directly by hand. However it would be a shame to not leverage the free and good Wicket plugins available for our IDE. The following is a brief overview of the most widely used plugins for each of the three main IDEs considered so far.

NetBeans NetBeans offers Wicket support through ‘NetBeans Plugin for Wicket’ hosted at http://plugins.netbeans.org/plugin/3586/wicket-1-4-support . This plugin is released under CDDL-1.0 license. You can find a nice introduction guide to this plugin at http://netbeans.org/kb/docs/web/quickstart-webapps-wicket.html .

Intellj IDEA For JetBrain IDEA we can use WicketForge plugin, hosted at Google Code http://code.google.com/p/wicketforge/ . The plugin is released under ASF 2.0 license.

Eclipse With Eclipse we can install one of the plugins that supports Wicket. As of the writing of this document, the most popular is probably Qwickie, available in the Eclipse Marketplace and hosted on Google Code at https://github.com/count-negative/qwickie/. QWickie is released under ASF 2.0 license.