Prerequisite: Eclipse and JDK setup

If Eclipse and JDK are not installed, follow this URL.

https://digitalappconsultancy.com/site/learning-java-hello-world-example/

The software used is as follows.

Eclipse 4.6.x
JDK 1.8.x
Apache Wicket 7.7.x
Apache Tomcat 8.5
Maven & Wicket (optional) Eclipse plug-in

Finally, the project looks like this:

step 1: Install Maven & Apache Wicket Plugin

Go to Eclipse-> Help-> Eclipse Marketplace and search for Maven & Wicket (optional). Install the plug-in. Eclipse will restart as part of the plug-in installation.

Step 2: Download Apache Tomcat

Go to the link below and download a specific Tomcat version (8.5 here). Download the zip file version and unzip the folder to C drive.

http://tomcat.apache.org/

Use command prompt to go to the tomcat director –> bin folder and run the startup batch file. You can see that the server is running.

To check the tomcat server – Type http: // localhost: 8080 in your browser.

Step 3: New Maven project

Create a new Maven project –> Create Simple Project – provide the following details:

Step 3: Update pom.xml and web.xml

Your web.xml looks like this:

<web-app xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://xmlns.jcp.org/xml/ns/javaee" xsi: schemaLocation = "http : //xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "id =" WebApp_ID "version =" 3.1 "> <display- name> MyWebApp </ display-name> <filter> <filter-name> MyWebAppApplication </ filter-name> <filter-class> org.apache.wicket.protocol.http.WicketFilter </ filter-class> <init-param > <param-name> applicationClassName </ param-name> <param-value> com.webapp.WicketApplication </ param-value> </ init-param> </ filter> <filter-mapping> <filter-name> MyWebAppApplication </ filter-name> <url-pattern> / * </ url-pattern> </ filter-mapping> </ web-app>

 

Update Maven pom.xml to download the Tomcat plugin, Apache wicket framework and Junit framework.

Caution : Maven is specified to build the war file <packaging> war </ packaging>.


            
                org.apache.tomcat.maven
                tomcat7-maven-plugin
                2.2
                
                    http://localhost:8080/manager/text
                    TomcatServer
                    /MyWebApp
                
            
        
    

    
        
        
            org.apache.wicket
            wicket-core
            7.7.0
        
        
        
        
            junit
            junit
            4.12
            test
        
        
        
        
            javax.servlet
            javax.servlet-api
            3.0.1
            provided
        
    
--><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/xsd/maven-4.0.0.xsd "> <modelVersion> 4.0.0 </ modelVersion> <groupId> MyWebApp </ groupId > <artifactId> MyWebApp </ artifactId> <version> 0.0.1-SNAPSHOT </ version> <packaging> war </ packaging> <build> <sourceDirectory> src / main / java </ sourceDirectory> <testSourceDirectory> src / test / java </ testSourceDirectory> <plugins> <plugin> <artifactId> maven-compiler-plugin </ artifactId> <version> 3.5.1 </ version> <configuration> <source> 1.8 </ source> <target> 1.8 < / target> </ configuration> </ plugin> <plugin> <artifactId> maven-war-plugin </ artifactId> <version> 3.0.0 </ version> <configuration> <warSourceDirectory> WebContent </ warSourceDirectory> </ configuration > </ plugin> <!-Tomcat Maven plugin to deploy war file-> <plugin> <groupId> org.apache.tomcat.maven </ groupId> <artifactId> tomcat7-maven-plugin </ artifactId> <version > 2.2 </ version> <config uration> <url> http: // localhost: 8080 / manager / text </ url> <server> TomcatServer </ server> <path> / MyWebApp </ path> </ configuration> </ plugin> </ plugins> < / build> <dependencies> <!-Apache Wicket Jars-> <dependency> <groupId> org.apache.wicket </ groupId> <artifactId> wicket-core </ artifactId> <version> 7.7.0 </ version > </ dependency> <!-https://mvnrepository.com/artifact/junit/junit-> <dependency> <groupId> junit </ groupId> <artifactId> junit </ artifactId> <version> 4.12 </ version> <scope> test </ scope> </ dependency> <!-Apache Wicket Testing need this jar-> <dependency> <groupId> javax.servlet </ groupId> <artifactId> javax.servlet-api </ artifactId> <version> 3.0.1 </ version> <scope> provided </ scope> </ dependency> </ dependencies> </ project>

Step 5: Create a Wicket Hello World

1. Create WicketApplication.java. This WicketApplication.java becomes the entry point class when the application starts.
2. Create LoginPage.java and LoginPage.html, which are components of the default home page (specified in WicketApplication.java). 3. WebContent –> web.xml in WEB-INF folder
Create

The following WicketApplication.java

package com.webapp; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.protocol.http.WebApplication; import com.webapp.page.LoginPage; public class WicketApplication extends WebApplication {@Override public Class <? extends WebPage> getHomePage () {return LoginPage.class;} @Override public void init () {super.init (); // add your configuration here}}

LoginPage.java provided below

package com.webapp.page; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; / ** * @author Niranjan Velagapudi * * / public class LoginPage extends WebPage {/ ** * * / private static final long serialVersionUID = 5946349607750478191L; public LoginPage () {add (new Label ("message", "Hello World!"));}}

LoginPage.html below

<? xml version = "1.0" encoding = "UTF-8"?> <html xmlns = "http://www.w3.org/1999/xhtml" xmlns: wicket = "http://wicket.apache.org "> <head> <title> Wicket Examples-helloworld </ title> <link rel =" stylesheet "type =" text / css "href =" style.css "/> </ head> <body> <span wicket: id = "message" id = "message"> Message goes here </ span> </ body> </ html>

Web.xml below

<? xml version = "1.0" encoding = "UTF-8"?> <web-app xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http: // xmlns .jcp.org / xml / ns / javaee "xsi: schemaLocation =" http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1 .xsd "id =" WebApp_ID "version =" 3.1 "> <display-name> MyWebApp </ display-name> <filter> <filter-name> MyWebApp </ filter-name> <filter-class> org.apache. wicket.protocol.http.WicketFilter </ filter-class> <init-param> <param-name> applicationClassName </ param-name> <param-value> com.webapp.WicketApplication </ param-value> </ init- param> </ filter> <filter-mapping> <filter-name> MyWebApp </ filter-name> <url-pattern> / * </ url-pattern> </ filter-mapping> </ web-app>

Step 6: Unit testing with the JUnit framework
An important feature comes with the Apache Wicket framework, which allows you to unitize test markup (HTML view) via JUnits.

Create a TestHomePage class under the src / test / java package as follows:

package com.test.page; import org.apache.wicket.util.tester.WicketTester; import org.junit.Before; import org.junit.Test; import com.webapp.WicketApplication; import com.webapp.page.LoginPage; / ** * @author Niranjan Velagapudi * * / public class TestHomePage {private WicketTester tester; @Before public void setUp () {tester = new WicketTester (new WicketApplication ());} @Test public void homepageRendersSuccessfully () {// start and render the test page tester.startPage (LoginPage.class); // assert rendered page class tester.assertRenderedPage (LoginPage.class);}}

Step 7: Configure and deploy Tomcat inside Maven

  1. Add maven settings.xml to access the Tomcat Server administration page for deployment. This xml will be available in maven user directory.m2

C: \ Users \ .m2 \ settings.xml looks like this:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
    http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository/>
    <interactiveMode/>
    <usePluginRegistry/>
    <offline/>
    <pluginGroups/>
    <servers>
        <server>
            <id>TomcatServer</id>
            <username>admin</username>
            <password>admin</password>
        </server>
    </servers>
    <mirrors/>
    <proxies/>
    <profiles/>
    <activeProfiles/>
</settings>

Finally, the project looks like this:

Using the specific goal “tomcat7: deploy” for the first time, right-click pom.xml and Run As-Maven and redeploy “tomcat7: redeploy”.

If the deployment is successful, the Hello World page should be displayed as follows:

アクセスURL – http://localhost:8080/MyWebApp

Detail is Apache Wicket Web Development See the Category article.

* This article This site Is translated.