Not able to start the Spring-Boot sample

Question!

I was trying out spring-boot samples. This is specifically the example spring-boot-sample-tomcat, that I have been trying to run.

As instructed, I have run mvn package and it is successful. But when running the jar java -jar target/spring-boot-sample-tomcat-0.5.0.BUILD-SNAPSHOT.jar, I am getting the below exception.

Please confirm if there is any jars which need to be put in the classpath. Or what to do to make it run.

Link to the pom.xml which is being used.

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
        at java.lang.Class.getDeclaredMethod(Class.java:1935)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at org.springframework.boot.loader.LaunchedURLClassLoader.findClass(LaunchedURLClassLoader.java:110)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:93)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:65)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 5 more
By : Kunal Jha


Answers

I just executed:

$ git fetch upstream
$ git merge upstream/master
Already up-to-date.
$ cd spring-boot-samples/spring-boot-sample-tomcat/
$ mvn clean package 
By : gregturn


This video can help you solving your question :)
By: admin