Introduction
This should be the beginning 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 either in a desktop or a web environment. My first approach was to use the Groovy framework Griffon for desktop and Apache Wicket for web. In the end, I changed Griffon to ScalaFX and Apache Tomcat to Open Liberty.
While ScalaFX was choosen because I feel more confortable using Scala, the decision behind why to use Open Liberty was more about learning something different. After reading comparisions between Application Servers, it seemed Open Liberty provided better performance compared to other Java runtimes (my choices had always been Apache Tomcat and Payara). So I wanted to prove to myself that this was true even though adopting IBM applications made me a false sense of betrayal of the spirit of open source.
So let's get started! ;).
Apache Wicket Project Creation.
Apache Wicket and Open Liberty. ummm. Where to start?.
1.- With maven, execute the following command changing whatever needed to adapt to the project to fit yours:
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
2.- Once the project skeleton is created, you may clean it just a little bit and add Open Liberty as a Jetty replacement as the Application Server. So, comment 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
3.- Add Open Liberty support as a build plugin and comment 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 make a two recursive folders named as liberty/config. Inside, a new file server.xml must be added 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 checking in the browser https://(server):9080/(web-app-name-found-in-web.xml)