sonar findbug missing class exception - sonarqube

while I am using sonar findbug for code review, it throws exception, claiming some classes are missing.
After some research, it's clear that the jars needed to build the project, should be included in the pom.xml for sonar's use.
to do that, sonar official web site suggesting, add dependencies,
com.opensymphony
xwork-core
2.1.6
system
${basedir}/.../xwork-core.jar
however, for me, it's always not working.
I am using windows, would anyone please enlighten me, how to configure, especially the systempath?
Here is the pom.xml, for one module of the project.
<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>DB</groupId>
<artifactId>Project1</artifactId>
<name>project1</name>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork-core</artifactId>
<version>2.1.6</version><!--installed into .m2 folder, local repository, then refer it-->
</dependency>
<dependency>
<groupId>dep</groupId>
<artifactId>dep1</artifactId>
<version>1.0</version> <scope>system</scope>
<systemPath>${basedir}/lib//asn.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>build-to/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
</project>
Thanks,
Jackie

Is your project already a maven project, or are you compiling things with ant or some other tool and then trying to get sonar to run against it? Sonar Light mode can be tricky with very complex projects. If you've got a multi-module project, i'd get the simplest project working under a local copy of sonar and then work towards adding more modules.
Additionally, I would try copying the files locally to a different directory that does not step up from ${basedir}. See if that helps. So ${basedir}/lib/xwork-core.jar something like that.
Perhaps for Sonar analysis, you can have a separate task copy the needed libraries to a temp folder that can be accessed appropriately, and then remove them once the analysis is complete.

i found out the problem. The official documentation of sonar is actually wrong.
"mvn sonar:sonar" would invoke the maven sonar plugin 2.0 beta, which won't enable the dependency of library jars work. Instead, call "mvn sonar3:sonar", invoke the maven sonar plugin 2.4.1, the latest version, works.

Related

OpenLiberty Maven Plugin

I am trying to create a runnale openliberty server as part of my release process. I have a a multi module maven project with a submodule dedicated to packaging the server as a runnable. When I do a mvn clean package a lovely executable jar is produced which bundles one of the other submodules (war). The problem I am facing is when I do a maven deploy to our asset repo the packaged server is being uploaded as a zip file rather than a jar file. Does anyone know how to get the deploy plugin to upload the jar?
Here is a sample pom file
<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>
<parent>
<groupId>au.com.xxxx.xxxx</groupId>
<artifactId>xxx-backend-parent</artifactId>
<version>0.0.16-SNAPSHOT</version>
</parent>
<artifactId>xxxx-openliberty-server</artifactId>
<packaging>liberty-assembly</packaging>
<name>fusion-openliberty-server</name>
<description>Runnable Jar containing xxxxand the OpenLiberty applictaion server</description>
<dependencies>
<!-- Package xxxx-application.war with server assembly -->
<dependency>
<groupId>au.com.xxx.xxx</groupId>
<artifactId>xxxx-application</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Enable liberty-maven-plugin -->
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>2.6.1</version>
<extensions>true</extensions>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-javaee8</artifactId>
<version>18.0.0.3</version>
<type>zip</type>
</assemblyArtifact>
<include>runnable</include>
<serverName>xxx</serverName>
<appsDirectory>apps</appsDirectory>
<serverEnv>${basedir}/src/main/resources/server.env</serverEnv>
<configFile>${basedir}/src/main/resources/server.xml</configFile>
<jvmOptionsFile>${basedir}/src/main/resources/jvm.options</jvmOptionsFile>
<bootstrapProperties>
<app.context.root>xxx-app</app.context.root>
<default.http.port>5000</default.http.port>
<default.https.port>5443</default.https.port>
</bootstrapProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>
I don't have an answer to your question but an explanation why this happens. Every packaging type (jar, war, liberty-assembly) defines a fixed extension for the artifact(s) it creates. The liberty-assembly types defines zip as it extension. This extension is used by the maven-install-plugin and maven-deploy-plugin regardless how the local file is names. I did quite some code digging but couldn't find a way to change this. It's probably sth. that only liberty-maven-plugin can change/fix.

Spring Boot fails to run maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter

Running maven (3.5.2) build of a Spring Boot 2.0.2.RELEASE applicaton (generated by web initialiser with web dependencies) fails executing the maven-surefire-plugin saying just:
Error: Could not find or load main class
org.apache.maven.surefire.booter.ForkedBooter
Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.booter.ForkedBooter
Why is this happening? Is it a problem in boot + surefire integration = a bug?
For reference, the dependencies that seem relevant are:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Workaround for the issue was to override Spring Boot's maven-surefire-plugin definition and set useSystemClassLoader to false. Read Surefire docs for more details
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
The <useSystemClassLoader>false</useSystemClassLoader> solution provideded by jediz did allow my surefire tests to run, but broke class loading in some of my Spring Boot integration tests.
The following maven-surefire-plugin configuration worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</configuration>
</plugin>
This is due to a known bug in the Maven Surefire plugin. It was fixed in version 3.0.0-M1, which was released in November 2018. So the simplest and most reliable fix is to upgrade which version of the plugin you use.
Updating the maven-surefire-plugin from 2.12.4 to 3.0.0-M1 worked for me. The project did not explicitly use the plugin, so I had to add a new plugin dependency.
<plugins>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
...
</plugins>
To me, the solution was to run mvn as
_JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true mvn clean compile package
Other ideas (giving the system property to the maven argument list, different changes in pom.xml, settings.xml) did not work.
Despite that it didn't contain the exact solution, also this answer was very helpful for me to make it clear, that it is an unfortunate cooperation of two independent, alone harmless bugs in the Ubuntu JDK and the Maven Surefire Plugin.
Recent Debian (buster) with the same JDK and Maven versions doesn't seem affected by the problem, but Ubuntu (xenial) did.
The exact solution is coming from this answer.
Update from the future: with Debian Buster is alles okay and this workaround is not needed any more.
I was able to remove the maven-surefire-plugin from my POM after adding this to the top of my POM (inside the <project> node)
<prerequisites>
<maven>3.6.3</maven>
</prerequisites>
Why do I think this is the right answer?
It specifies the version of Maven that Maven recommends using: https://maven.apache.org/download.cgi
when you run mvn versions:display-plugin-updates it shows that it's taking the maven-surefire-plugin 3.0.0-M3 from super-pom, which so far seems to have this issue fixed.
You don't have to manage individual plugin versions independently going forward. Just your minimum maven version which controls the super-pom version.
Adding this to the maven-surefire-plugin I resolved the problem:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>0</forkCount>
</configuration>
</plugin>

How to create a complete `.war` file with pom.xml

I have a web service project (SOAP) implemented in Java, as a Maven project. I want to create a .war to deploy into a Tomcat.
To create the .war, I always used the Eclipse Juno interface (Right click -> Export -> WAR File). The Eclipse is configured with Tomcat 7 and Axis 1.5.6. Using this method I deploy the .war file created and everything is fine! The main page of the application looks like below:
[![Web Service main page][1]][1]
In this page, I can explore the services, methods and WSDL files. This is what I call complete .war file.
Now, I migrated my web service to Maven, in order to use it with Jenkins, to automate the deploys, tests, etc.
I tried for two full days create a pom.xml which will create the same .war file that was created with Eclipse, but I was not successful. When I deploy the .war created using the pom.xml on a Tomcat and access the localhost:8080/SOAPExample/, it shows Error 404. The Maven build of the .war and the Tomcat deploy was successful. I understood that the service page was not created, but the web service was deployed successfuly.
I used some of the tutorials available in the internet, like the below, but in all cases the .war created by Maven is incomplete:
http://crunchify.com/how-to-create-a-war-file-from-eclipse-using-maven-plugin-apache-maven-war-plugin-usage/
https://www.mkyong.com/maven/how-to-deploy-maven-based-war-file-to-tomcat/
It looks like I'm missing some dependency configuration into the pom.xml, or something like that. Here is my pom.xml. I also think it is missing some axis2 configuration.
<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>com.test</groupId>
<artifactId>SOAPExample</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>SOAPExample</name>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
Here is my project sctructure:
[[![Project Folder Structure]][2][2]]
There is no tutorial in the internet explaining how to configure a pom.xml to create a complete .war file. Could some good soul help me?

A required class is missing: org.apache.maven.plugin.jar.JarMojo

After I upgraded my Ubuntu to 13.10 version I reinstalled the latest Eclipse Kepler.
I have a simple JSE app. It used to work in Eclipse before and it's still working through terminal (mvn clean install), but now I'm getting an error in Eclipse:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar
(default-jar) on project files: Execution default-jar of goal org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar
failed: Unable to load the mojo 'jar' in the plugin 'org.apache.maven.plugins:maven-jar-plugin:2.3.2'.
A required class is missing: org.apache.maven.plugin.jar.JarMojo
I already tried a few things:
I checked jvm version configured in eclipse.ini: -vm /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
I tried 3.0.5 and 3.1.1 maven versions;
I right-clicked the project and selected Maven->Update Project.
I checked the java version in the project properties menu: it's pointing to /usr/lib/jvm/java-6-openjdk-amd64, although it always changes back to JavaSE-1.6(jre6) after I follow the previous step (Update Project).
Set java source and target version to 1.6 in the maven-compiler-plugin in pom.xml configuration.
Tried different jdk versions (openjdk6, openjdk7, oracle jdk6 and oracle jdk7);
I also tried to download JBoss Devstudio and also cleaning workspace by deleting .metadata folder.
Unfortunately nothing worked.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>br.uel.ati.util</groupId>
<artifactId>files</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jse-template</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<description>Template da Diretoria de Desenvolvimento de Sistemas para bibliotecas utilizadas por projetos EJB e Web.</description>
<organization>
<name>Universidade Estadual de Londrina</name>
<url>http://uel.br/ati</url>
</organization>
</project>
Anyone know what I should try to solve this issue?
I found the solution here: How can i resolve plugin problem in maven:' Unable to load mojo'
Apparently there was a corrupted library in maven repository. I just deleted repository/org folder, download it again and updated (Maven->Update Project + F5) my maven projects inside Eclipse.
I'm still curious about why it was working by command line. Maybe a new maven repository was created when I installed it by apt-get.

"webxml attribute is required" error in Maven

I am getting the following error:
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
I have got web.xml in right place which is projectname\src\main\webapp\WEB-INF\web.xml
What could be causing this?
It would be helpful if you can provide a code snippet of your maven-war-plugin.
Looks like the web.xml is at right place, still you can try and give the location explicitly
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
This solution works for me (I was using 2.2 before). Also, I am using Java Based Configuration for Servlet 3.0 and no need to have web.xml file.
It works perfectly for me too.
<project>
.....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is because you have not included web.xml in your web project and trying to build war using maven. To resolve this error, you need to set the failOnMissingWebXml to false in pom.xml file.
For example:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Please see the blog for more details: https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html
If you are migrating from XML-based to Java-based configuration and you have removed the need for web.xml by implementing WebApplicationInitializer, simply remove the requirement for the web.xml file to be present.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
...
</configuration>
The value of my webXml tag needed to look like this in order to work:
<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
I had the exact same problem and i solved it like this :
Make a new folder named WEB-INF under src/main/webbapp then
Right Click on your Project -> Java EE Tools -> Generate Deployment Descriptor Stub
This should generate your web.xml
I hope this helps by solving your problem :D
It does look like you have web.xml in the right location, but even so, this error is often caused by the directory structure not matching what Maven expects to see. For example, if you start out with an Eclipse webapp that you are trying to build with Maven.
If that is the issue, a quick fix is to create a
src/main/java and a
src/main/webapp directory (and other directories if you need them) and just move your files.
Here is an overview of the maven directory layout:
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
🔴 failOnMissingWebXml since 2020
All other answers about might be obsolete because the default value used by the maven-war-plugin changed:
Starting with 3.0.1, this property defaults to false if the project depends on the Servlet 3.0 API or newer.
So the ONLY thing you have to do is to add
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
Example:
<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>foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
As per the documentation, it says : Whether or not to fail the build if the web.xml file is missing. Set to false if you want you WAR built without a web.xml file. This may be useful if you are building an overlay that has no web.xml file.
Default value is: true.
User property is: failOnMissingWebXml.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<extensions>false</extensions>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Hope it makes more clear
It worked for me too.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
This is an old question, and there are many answers, most of which will be more or less helpful; however, there is one, very important and still relevant point, which none of the answers touch (providing, instead, different hacks to make build possible), and which, I think, in no way has a less importance.. on the contrary.
According to your log message, you are using Maven, which is a Project Management tool, firmly following the conventions, over configuration principle.
When Maven builds the project:
it expects your project to have a particular directory structure, so that it knows where to expect what. This is called a Maven's Standard Directory Layout;
during the build, it creates also proper directory structure and places files into corresponding locations/directories, and this, in compliance with the Sun Microsystems Directory Structure Standard for Java EE [web] applications.
You may incorporate many things, including maven plugins, changing/reconfiguring project root directory, etc., but better and easier is to follow the default conventions over configuration, according to which, (now is the answer to your problem) there is one simple step that can make your project work: Just place your web.xml under src\main\webapp\WEB-INF\ and try to build the project with mvn package.
If you change the default project path, you must specify the location of the web.xml file, for example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<webXml>src\main\web\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
mvn-war-plugin 2.3 fixes this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
...
I have had the same error on the test server but not in local. After a few minutes, I discovered that the IDE wasn't synchronized with the pom.xml. Here is how I solve it:
Re-Generate the deployment descriptor with Eclipse
Right click on your project folder
In the contextual menu, choose "Java EE Tools" then "Generate Deployment Descriptor Stub"
It will create the web.xml.
Re-Generate the deployment descriptor with IntelliJ
Right click on your project folder
In the contextual menu, choose "Open Module Settings", then click on the + to add the web deployment descriptor.
Then your can change the path to your descriptor or the Web Ressource Directoriesand the on the right side.
Then you will get something like:
Make sure pom.xml is placed properly in Project folder. and not inside target folder or any where else.
Looks like pom.xml is not relatively aligned.
Was your folder structure altered so the file is no-longer at /src/main/webapp/WEB-INF/web.xml ?
To resolve this issue, I gave my web folder the name webapp and placed it inside the src/main. Maven seems to look for web.xml by default at /src/main/webapp/WEB-INF/web.xml. If you do this then you don't need to explicitly tell maven where web.xml is. And if you've altered your folder structure and your build recently stopped working, this could be why.
Note: This is an old post but the posted solutions don't point out why a working build would suddenly stop working.
This error occurs because you tell to Maven to pakage files to war.
<packaging>war</packaging>
Do you really need war? If not, put jar there.
Here is full code:
<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>
<version>1.0-SNAPSHOT</version>
<groupId>com.your.groupid</groupId>
<artifactId>artifactid</artifactId>
<packaging>jar</packaging>
I encountered this message while trying to package a Spring Boot project as a WAR file and deploying that WAR file in a standalone Tomcat instance.
I used Spring Intializr to generate the initial pom.xml and related artifacts.
The problem was that in that pom.xml (Spring version 2.6.+), this dependency was in place.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
I had to replace it with this one:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
And also added this dependency with scope of "provided"
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Also, of course, changed the packaging
<packaging>war</packaging>
Make sure to run mvn install before you compile your war.
There are two things to note regarding packaging.
Packaging to a war file will require you define the web.xml file in the appropriate folder as described by Catalin Ciolocoiu.
But changing the package type to jar would not need that structure and should work straight away.

Resources