Introduction
This is the first in a series of articles explaining how to use Apache Wicket with Open Liberty. Some time ago I started two different applications to handle the dar command in both desktop and web environments. My initial approach was to use the Groovy framework Griffon for the desktop application and Apache Wicket for the web interface. Eventually, I switched from Griffon to ScalaFX and from Apache Tomcat to Open Liberty.
While ScalaFX was chosen because I feel more comfortable using Scala, the decision to use Open Liberty was driven by a desire to learn something new. After reading comparisons between application servers, Open Liberty appeared to offer better performance compared to other Java runtimes (my previous choices had always been Apache Tomcat and Payara). So I wanted to verify this for myself, even though adopting IBM software gave me a slight, false sense of betraying the open-source spirit.
So let's get started! ;)
Apache Wicket Project Creation
Apache Wicket and Open Liberty together. Where do we start?
- Using Maven, execute the following command (adjusting parameters as needed for your project):
mvn archetype:generate -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart \
-DarchetypeVersion=10.1.0 -DgroupId=net.sxgio -DartifactId=dar-web-app -DarchetypeRepository=https://repository.apache.org/ -DinteractiveMode=false
- Once the project skeleton is generated, you can clean it up slightly and configure Open Liberty as your application server instead of Jetty. Comment out the following lines in your
pom.xml:
<!-- JAVAX J2EE 8 DEPENDENCY -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
...
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<scope>test</scope>
<version>${jetty9.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${jetty9.version}</version>
<scope>test</scope>
</dependency>
<!-- uncomment if WebSocket support is needed
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>${jetty9.version}</version>
<scope>test</scope>
</dependency>
Open Liberty Support
- Add Open Liberty support as a build plugin and comment out Jetty support:
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>${liberty.version}</version>
<configuration>
<serverName>test</serverName>
</configuration>
<!-- Specify configuration, executions for liberty-maven-plugin -->
</plugin>
<!--plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty9.version}</version>
<configuration>
<systemProperties>
<systemProperty>
<name>maven.project.build.directory.test-classes</name>
<value>${project.build.directory}/test-classes</value>
</systemProperty>
</systemProperties>
<jettyXml>${project.basedir}/src/test/jetty/jetty.xml,${project.basedir}/src/test/jetty/jetty-ssl.xml,${project.basedir}/src/test/jetty/jetty-http.xml,${project.basedir}/src/test/jetty/jetty-https.xml</jettyXml>
</configuration>
</plugin-->
Configuring Open Liberty
Inside src/main, create two nested folders named liberty/config. Inside, create a new file named server.xml with the following content:
<server description="[YOUR APP NAME]">
<featureManager>
<feature>servlet-4.0</feature>
</featureManager>
<variable name="default.http.port" defaultValue="[HTTP_PORT_BY_DEFAULT: 9080]"/>
<variable name="default.https.port" defaultValue="[HTTPS_PORT_BY_DEFAULT: 9443]"/>
<variable name="app.context.root" defaultValue="[Root in OpenLiberty: wicket-app-1.0-SNAPSHOT]"/>
<!-- tag::httpEndpoint[] -->
<httpEndpoint httpPort="${default.http.port}"
httpsPort="${default.https.port}" id="defaultHttpEndpoint" host="*" />
<!-- end::httpEndpoint[] -->
<webApplication id="WicketApp" location="[war file to deploy: wicket-app-1.0-SNAPSHOT.war]" contextRoot="${app.context.root}" />
</server>
Running the application
That's all! Now we can test the Wicket project in Open Liberty by running the following command:
mvn io.openliberty.tools:liberty-maven-plugin:dev
And accessing it in the browser at: http://localhost:9080/[app-context-root]