Tiven Wang
chevron_rightServlet chevron_rightMaven chevron_rightTomcat

Cloud Training 1 - Create Maven Project and Deploy to Tomcat

Wang Tiven April 24, 2017
425 favorite favorites
bookmark bookmark
share share

Installation

JDK8

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

JAVA_HOME PATH

Check Java

java -version

Tomcat8

http://tomcat.apache.org/download-80.cgi

CATALINA_HOME

Startup Tomcat

%TOMCAT HOME%\bin\startup.bat

http://127.0.0.1:8080/

http://127.0.0.1:8080/examples

Maven3

https://maven.apache.org/download.cgi?Preferred=http%3A%2F%2Fmirrors.tuna.tsinghua.edu.cn%2Fapache%2F

PATH

Check Maven

mvn -v

Create Project

1 Generate Project by Maven

mvn archetype:generate -DgroupId=com.tiven -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

2 Build and Package

mvn package

3 Deploy to Tomcat Container

Deploy war into tomcat apache-tomcat-8.5.14\webapps

4 Check your Web Application - jsp

http://127.0.0.1:8080/WebApp/

Create a Servlet

1 Create HelloCloud class

package com.tiven;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloCloud extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Hello Cloud!</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Hello Cloud!</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

2 Add servlet configures in web.xml

<servlet>
    <servlet-name>HelloCloud</servlet-name>
    <servlet-class>com.tiven.HelloCloud</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>HelloCloud</servlet-name>
    <url-pattern>/servlets/HelloCloud</url-pattern>
</servlet-mapping>

3 Add Servlet Dependencies in pom.xml

<dependencies>
  ...

  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

4 Re Build and Package

mvn clean packge

5 Check the Servlet

http://127.0.0.1:8080/WebApp/servlets/HelloCloud

Eclipse IDE Support

mvn eclipse:eclipse -Dwtpversion=2.0

import into eclipse

add tomcat7 plugin in pom.xml

<plugins>
  <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
  </plugin>
</plugins>

mvn tomcat7:run

Debug in Eclipse IDE

mvndebug tomcat7:run

Run Remote Java Application in Debug Configurations at local port 8000

debug in servlet

download source codes for maven dependencies:

mvn dependency:sources mvn dependency:resolve -Dclassifier=javadoc

or Configure them in eclipse

Similar Posts

  • Try CloudFoundry Try CloudFoundry
  • Maven Best Practices Maven Best Practices
  • Unit Test by Spring MVC Test Framework Testing is an integral part of enterprise software development. Dependency Injection should make your code less dependent on the container than it would be with traditional Java EE development. This topic introduce how to create Unit Test by Spring MVC Test Framework for Java project on HCP
  • Apply Spring Data JPA to Java Project on HCP Spring Data’s mission is to provide a familiar and consistent, Spring-based programming model for data access while still retaining the special traits of the underlying data store. Spring Data JPA, part of the larger Spring Data family, makes it easy to easily implement JPA based repositories. This module deals with enhanced support for JPA based data access layers. It makes it easier to build Spring-powered applications that use data access technologies.
  • Apply Spring Architecture to Java Project on HCP The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform. Although the framework does not impose any specific programming model, it has become popular in the Java community as an alternative to, replacement for, or even addition to the Enterprise JavaBeans (EJB) model. I will show you how to apply Spring Frameworks to Java project on HANA Cloud Platform.
  • Persistence Service for Java Maven Project on HCP The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. JPA was defined as part of the EJB 3.0 specification as a replacement for the EJB 2 CMP Entity Beans specification. In this topic I will show you how to create persistence service for Java project on HCP using Java Persistence API (JPA) and it's implementation EclipseLink

Comments

Back to Top