Issue
I've recently prepared spring-boot configuration to work properly on a standalone jetty.
I've encountered a strange behavior from maven. It adds jars to my .war archive which are not present in mvn dependency:tree
. I've worked around the problem by adding this to my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
</configuration>
</plugin>
But that's obviously an ugly solution.
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>com.pretius</groupId>
<artifactId>springBootJettyExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring-Boot jetty example app</name>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.BUILD-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
<build>
<finalName>spbj-example</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
mvn dependency:tree:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Spring-Boot jetty example app 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ springBootJettyExample ---
[INFO] com.pretius:springBootJettyExample:war:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile
[INFO] | | +- org.springframework:spring-core:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.16:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.26:compile
[INFO] | | \- org.hibernate:hibernate-validator:jar:5.2.1.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.1.0:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.1:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.1:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.6.1:compile
[INFO] | +- org.springframework:spring-web:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-aop:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | | \- org.springframework:spring-context:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-expression:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jetty:jar:1.3.0.BUILD-SNAPSHOT:provided
[INFO] | +- org.eclipse.jetty:jetty-servlets:jar:9.2.13.v20150730:provided
[INFO] | | +- org.eclipse.jetty:jetty-continuation:jar:9.2.13.v20150730:provided
[INFO] | | +- org.eclipse.jetty:jetty-http:jar:9.2.13.v20150730:provided
[INFO] | | +- org.eclipse.jetty:jetty-util:jar:9.2.13.v20150730:provided
[INFO] | | \- org.eclipse.jetty:jetty-io:jar:9.2.13.v20150730:provided
[INFO] | +- org.eclipse.jetty:jetty-webapp:jar:9.2.13.v20150730:provided
[INFO] | | +- org.eclipse.jetty:jetty-xml:jar:9.2.13.v20150730:provided
[INFO] | | \- org.eclipse.jetty:jetty-servlet:jar:9.2.13.v20150730:provided
[INFO] | | \- org.eclipse.jetty:jetty-security:jar:9.2.13.v20150730:provided
[INFO] | | \- org.eclipse.jetty:jetty-server:jar:9.2.13.v20150730:provided
[INFO] | +- org.eclipse.jetty.websocket:websocket-server:jar:9.2.13.v20150730:provided
[INFO] | | +- org.eclipse.jetty.websocket:websocket-common:jar:9.2.13.v20150730:provided
[INFO] | | | \- org.eclipse.jetty.websocket:websocket-api:jar:9.2.13.v20150730:provided
[INFO] | | +- org.eclipse.jetty.websocket:websocket-client:jar:9.2.13.v20150730:provided
[INFO] | | \- org.eclipse.jetty.websocket:websocket-servlet:jar:9.2.13.v20150730:provided
[INFO] | | \- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] | \- org.eclipse.jetty.websocket:javax-websocket-server-impl:jar:9.2.13.v20150730:provided
[INFO] | +- org.eclipse.jetty:jetty-annotations:jar:9.2.13.v20150730:provided
[INFO] | | +- org.eclipse.jetty:jetty-plus:jar:9.2.13.v20150730:provided
[INFO] | | | \- org.eclipse.jetty:jetty-jndi:jar:9.2.13.v20150730:provided
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.2:provided
[INFO] | | +- org.ow2.asm:asm:jar:5.0.1:provided
[INFO] | | \- org.ow2.asm:asm-commons:jar:5.0.1:provided
[INFO] | | \- org.ow2.asm:asm-tree:jar:5.0.1:provided
[INFO] | +- org.eclipse.jetty.websocket:javax-websocket-client-impl:jar:9.2.13.v20150730:provided
[INFO] | \- javax.websocket:javax.websocket-api:jar:1.0:provided
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-jdbc:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-tx:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.aspectj:aspectjrt:jar:1.8.6:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.8.6:compile
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] | | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | | +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] | | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | | \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] | | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:1.9.0.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:1.11.0.RELEASE:compile
[INFO] | | +- org.springframework:spring-orm:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] | | \- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] | \- org.springframework:spring-aspects:jar:4.2.2.BUILD-SNAPSHOT:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] +- org.hsqldb:hsqldb:jar:2.3.3:runtime
[INFO] \- org.slf4j:slf4j-log4j12:jar:1.7.12:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] \- log4j:log4j:jar:1.2.17:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.746 s
[INFO] Finished at: 2015-10-05T09:36:47+02:00
[INFO] Final Memory: 21M/309M
[INFO] ------------------------------------------------------------------------
(Yes, there is one tomcat lib in the tree, but there are several added to .war)
Unwanted jars:
tomcat-embed-core-8.0.26.jar
tomcat-embed-logging-juli-8.0.26.jar
tomcat-embed-websocket-8.0.26.jar
tomcat-jdbc-8.0.26.jar
tomcat-juli-8.0.26.jar
Here's a link to the sample application.
What is adding the tomcat*
jars to my .war? How can I stop it doing so?
Solution
Well when I run maven package this pom produces two war files one named "spbj-example.war" for running with
org.springframework.boot.loader.WarLauncher
and another one named "spbj-example.war.original".
You should use the second war which doesn't contain anything related to servers. The first one contains a lib directory in which you have jar files to run a server like "jetty-server-9.2.13.v20150730.jar" and lots of others.
So most likey problem is related to your dirty "target" directory. You should use
mvn clean package/install
Answered By - cool
Answer Checked By - Robin (JavaFixing Admin)