0
votes

I am making war packaging of my spring boot. made spring boot starter tomcat as provided, removed spring boot maven plugin.

But I still see tomcat jdbc and tomcat juli, to name a few (even junit, but it could be from other custom dependencies, so discounting this for this question). I am using logback, but I see log4j over slf4j from starter web.

Can I ask, how to skip unwanted jars and keep my package nice and tidy

1
tomcat-jdbc is a connection pool and has no relation to the tomcat runtime. Excluding the tomcat runtime will still include this connection pool for older Spring Boot versions as there it is the default connection pool used, newer versions ship with Hikari. - M. Deinum
@MDeinum, Thanks. I understand tomcat-jdbc is connection pooling related and not part of starter-tomcat. We use websphere and see if I have to exclude tomcat-jdbc from starter-jdbc. Is there a way, I can create my package as close as possible to Spring. craftsmen.nl/… - Kris Swat
The fact that a jar is present doesn't mean it will be loaded. imho you are optimizing the wrong things. Also wha tyou are linking to doesn't apply here as you are using WebSphere and not spring boot with an embedded container. - M. Deinum

1 Answers

0
votes

Maven has the concept of "scope" for dependencies. You probably know the scope test which is used for unit test dependencies which should not go into the final product. Use this scope for junit.

What you need is the scope provided for the Tomcat dependencies. This tells Maven: "Don't include it; when the code is run, someone else will make sure this dependency is on the classpath".

The dependency log4j-over-slf4j is necessary when one of your dependencies still uses log4j to log. log4j-over-slf4j contains the code to redirect those calls to logback.

Now you will face the case where you can't change the scope because it's in a POM of someone else.

The correct solution here is to define the dependency with the correct scope (and version) in a dependencyManagement element in your POM. This definition will be used when any POM asks for this group+artifactId. So even when some deep dependency of Spring Boot pulls that in, your WAR will be build with the version and scope from the dependencyManagement element.

See also: