You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Olivier Peyrusse <ki...@gmail.com> on 2016/08/29 14:46:56 UTC

Scanning jars with Manifest with tomcat-embed

Hello everyone,

In my company, one of our Maven projects create a war that we usually
deploy in tomcat.
For debug purpose, we added a test class that instanciate an embed Tomcat
instance to run the application from an IDE (Intellij in my case).

Using tomcat-emded-core.8.5.4, at startup, it gives me a lot of warnings
like:
*Aug 29, 2016 11:22:57 AM org.apache.tomcat.util.scan.StandardJarScanner
scan*

*WARNING: Failed to scan
[file:/home/olivier/maven/repo/net/sf/jung/jung-graph-impl/2.0.1/jung-api-2.0.1.jar]
from classloader hierarchyjava.io.FileNotFoundException:
/home/olivier/maven/repo/net/sf/jung/jung-graph-impl/2.0.1/jung-api-2.0.1.jar
(No such file or directory)*

Given maven repository architecture, it is logical that the scanner can't
find the jar as we are looking for *jung-api *in* jung-graph-impl *folder
*.*
If I instead look in
*/home/olivier/maven/repo/net/sf/jung/jung-api/2.0.1/jung-api-2.0.1.jar,* I
correctly find the wanted jar.

After investigating the troubling jars and StandardJarScanner source code,
I discovered that *jung-graph-impl* includes a MANIFEST file with the
Class-Path attribute containing
*jung-api*, among others.
When this attribute is defined, the scanner reads the path of the jar
containing the MANIFEST, and uses it to get the jars mentionned in the
classpath.

*Jar file:
/home/olivier/maven/repo/net/sf/jung/jung-graph-impl/2.0.1/jung-api-2.0.1.jar*

*-> Jar path: /home/olivier/maven/repo/net/sf/jung/jung-graph-impl/2.0.1/*
*-> Looking for
/home/olivier/maven/repo/net/sf/jung/jung-graph-impl/2.0.1/jung-api-2.0.1.jar*

For Tomcat application (installed on a computer), this is fine as wars
shipped all their needed jars in WEB-INF/lib. Thus, the algo to look for
another jar is ok.
This is less ok when Tomcat is run from an IDE, where the classpath is made
from various locations.
Eg: /opt/java/jdk1.8.0_92/bin/java -Dfile.encoding=UTF-8
*-classpath
/opt/java/jdk1.8.0_92/jre/lib/charsets.jar:/opt/java/jdk1.8.0_92/jre/lib/deploy.jar:[...
many
jars]:/home/olivier/maven/repo/net/sf/jung/jung-graph-impl/2.0.1/jung-graph-impl-2.0.1.jar:/home/olivier/maven/repo/net/sf/jung/jung-api/2.0.1/jung-api-2.0.1.jar:[...
more jars]*
MyServer

Is this a bug or is there something wrong with my Tomcat config or the jars
I use ?

I attached to the ticket the main class of my application, to show how I
create my Tomcat instance.
tomcat-embed is imported in my project by requiring the following maven
dependency:
+- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.4:test
|  \- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.4:test

Thanks a lot for the help