Spring Boot – Deploy WAR file to Tomcat

In this article, we will show you how to create a Spring Boot traditional WAR file and deploy to a Tomcat servlet container. In Spring Boot, to create a WAR for deployment, we need 3 steps: Extends SpringBootServletInitializer Marked the embedded servlet container as provided. Update packaging to war Tested with Spring Boot 2.1.2.RELEASE Tomcat …

Read more

Spring Boot – Which main class to start

If Spring Boot project contains multiple main classes, Spring Boot will fail to start or packag for deployment. Terminal $ mvn package #or $ mvn spring-boot:run Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run (default-cli) Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run failed: Unable to find a single main class from the following candidates [com.mkyong.Test, com.mkyong.SpringBootWebApplication] -> [Help 1] Maven …

Read more

Spring Boot Hello World Example – JSP

A Spring Boot web application example, using embedded Tomcat + JSP template, and package as an executable WAR file. Technologies used : Spring Boot 1.4.2.RELEASE Spring 4.3.4.RELEASE Tomcat Embed 8.5.6 Maven 3 Java 8 1. Project Directory Create the following folders manually : 2. Project Dependencies Maven example. Read comments for self-explanatory. pom.xml <?xml version="1.0" …

Read more

Maven – webxml attribute is required

Maven package a web application and hits the following error message : $ mvn package //… [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring4-mvc-maven-ajax-example: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1] Solution 1. For servlet container < 3, make sure WEB-INF/web.xml file ...

Read more

Gradle War Plugin – Change output WAR filename

In Gradle, the WAR plugin will generate the final WAR file with the following pattern: ${baseName}-${appendix}-${version}-${classifier}.${extension} Example : hello.1.0.war To change the default WAR filename, update war.archiveName. For example : build.gradle project(‘:web’) { apply plugin: ‘war’ war { archiveName ‘hello-gradle.war’ } dependencies { compile project(‘:core’) providedCompile ‘javax.servlet:servlet-api:2.5’ providedCompile ‘org.apache.tomcat:tomcat-jsp-api:7.0.55’ //… } } Build it… $ …

Read more

Ant – Spring MVC and WAR file Example

In this tutorial, we will show you how to use Ant build script to manage a Spring MVC web application project, create a WAR file and deploy to Tomcat. Technologies used : Eclipse 4.2 JDK 1.7 Ant 1.9.4 Ant-Ivy 2.4 logback 1.1.2 jstl 1.2 Spring 4.1.3.RELEASE Tomcat 7 1. Project Directory Review the final project …

Read more

How to deploy Maven based war file to Tomcat

In this tutorial, we will show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat, both in Tomcat 6 and 7. Libraries used : Maven 3 Tomcat 6.0.37 Tomcat 7.0.53 Tomcat 7 Deploy URL = http://localhost:8080/manager/text Command = mvn tomcat7:deploy Tomcat 6 Deploy URL = http://localhost:8080/manager/ Command = mvn …

Read more

How to unzip a WAR file in Java

In J2EE web development, Web Application Archive(WAR) file is just a normal JAR file, which consists all of your web application components like, servlets, Java classes, libraries, resources and etc. Read Wiki for detail. Problem Current web application WAR file is generated via Ant or Maven tool, copy to *nix environment for deployment, but no …

Read more