无法从类加载器层次结构中扫描某些Jars

时间:2017-08-01 09:24:14

标签: maven tomcat spring-boot vaadin

我在我的项目中使用Spring Boot 2.0.0.M2和Vaadin 8.1.0.rc1。由于我需要使用自定义小部件,因此我在项目中添加了vaadin-client-compiler依赖项。第一个奇怪的事情是嵌入式Tomcat自动被嵌入式Jetty取代。第二个问题是我在应用程序初始化期间开始收到类似这样的警告:

2017-08-01 11:07:27.822  WARN 1012 --- [           main] o.a.tomcat.util.scan.StandardJarScanner  : Failed to scan [file:/Users/mac/.m2/repository/com/vaadin/vaadin-sass-compiler/0.9.13/sac-1.3.jar] from classloader hierarchy

java.io.FileNotFoundException: /Users/mac/.m2/repository/com/vaadin/vaadin-sass-compiler/0.9.13/sac-1.3.jar (No such file or directory)
    at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_101]
    at java.util.zip.ZipFile.<init>(ZipFile.java:219) ~[na:1.8.0_101]
    at java.util.zip.ZipFile.<init>(ZipFile.java:149) ~[na:1.8.0_101]
    at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_101]
    at java.util.jar.JarFile.<init>(JarFile.java:130) ~[na:1.8.0_101]
    at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:60) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
    at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:43) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
    at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:327) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:277) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
    at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [apache-jsp-8.5.9.1.jar:2.3]
    at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [apache-jsp-8.5.9.1.jar:2.3]
    at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [apache-jsp-8.5.9.1.jar:2.3]
    at org.springframework.boot.web.embedded.jetty.JasperInitializer.doStart(JasperInitializer.java:91) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131) [jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105) [jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) [jetty-server-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:120) [jetty-server-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:844) [jetty-server-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:344) [jetty-servlet-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1501) [jetty-webapp-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1463) [jetty-webapp-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785) [jetty-server-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261) [jetty-servlet-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545) [jetty-webapp-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131) [jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.server.Server.start(Server.java:452) [jetty-server-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105) [jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) [jetty-server-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.server.Server.doStart(Server.java:419) [jetty-server-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
    at org.springframework.boot.web.embedded.jetty.JettyWebServer.initialize(JettyWebServer.java:103) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.web.embedded.jetty.JettyWebServer.<init>(JettyWebServer.java:81) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getJettyWebServer(JettyServletWebServerFactory.java:537) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:175) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:161) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:134) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) [spring-context-5.0.0.RC2.jar:5.0.0.RC2]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M2.jar:2.0.0.M2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M2.jar:2.0.0.M2]

仍然应用程序正常工作:我只是想摆脱这些警告。所以我决定放弃Tomcat而不是Jetty并将Jetty排除在外:

<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-client-compiler</artifactId>
    <version>${vaadin.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
        </exclusion>
    </exclusions>
</dependency>

完成后,警告并没有消失,但有所改变:

java.io.FileNotFoundException: /Users/mac/.m2/repository/com/vaadin/vaadin-sass-compiler/0.9.13/sac-1.3.jar (No such file or directory)
    at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_101]
    at java.util.zip.ZipFile.<init>(ZipFile.java:219) ~[na:1.8.0_101]
    at java.util.zip.ZipFile.<init>(ZipFile.java:149) ~[na:1.8.0_101]
    at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_101]
    at java.util.jar.JarFile.<init>(JarFile.java:130) ~[na:1.8.0_101]
    at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:60) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:338) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [apache-jsp-8.5.9.1.jar:2.3]
    at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [apache-jsp-8.5.9.1.jar:2.3]
    at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [apache-jsp-8.5.9.1.jar:2.3]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_101]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_101]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_101]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]

我在Vaadin论坛上发现thread建议使用8.0.32版本的Tomcat来修复它。当我切换到它时,应用程序根本停止工作:

Caused by: java.lang.ClassNotFoundException: org.apache.juli.WebappProperties
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 29 more

然后我发现一些其他线程建议使用Tomcat 8.5.5,因为它有一些修复(不记得线程的URL)。我试过8.5.5:警告回来了。然后我也尝试了8.5.19甚至9.0.0.M25,结果相同。

问题出在哪里:Spring,Tomcat,Vaadin或Maven依赖版本?我该如何解决?这些警告不会使应用程序失败,但我不希望它们出现在我的启动日志中。

更新

以下是我的POM,应用级和完整mvn spring-boot:run输出:https://gist.github.com/dtitov/ce9c098c8aa64073b3a22d2178f9aac7

1 个答案:

答案 0 :(得分:2)

免责声明:可能这更适合作为评论,但它不适合空间。

1)您可以使用稳定的Vaadin 8.1.0vaadin-spring-boot-starter 2.0.1。 Vaadin模块版本由vaadin-bom管理(${vaadin.version}是我的pom中的属性,其值为8.1.0):

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <version>${vaadin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

在此之后,每次更改Vaadin版本时都不需要更改其版本(除非您确实需要使用特定版本):

<dependency>
     <groupId>com.vaadin</groupId>
     <artifactId>vaadin-spring-boot-starter</artifactId>
 </dependency>

2)您应该使用与Vaadin版本相同的vaadin-maven-plugin来避免widgetset版本不匹配/问题。您使用的是Vadin 8.1.0,但插件版本是8.0.6。您可以使用<version>${vaadin.version}</version>同步它们。

3)根据docs,vaadin-client-compiler仅在编译时使用,不应与您的应用程序一起部署:

  

<强> vaadin-客户编译器8.x.x.jar
  Vaadin客户端编译器是一个Java-to-JavaScript编译器,允许构建客户端模块,例如服务器端应用程序所需的客户端引擎(窗口小部件集)。例如,需要编译器将附加组件编译到应用程序窗口小部件集,如“使用Vaadin加载项”中所述。

     

有关编译器的详细信息,请参阅“编译客户端模块”。 请注意,您不应将此库与Web应用程序一起部署。

您可以将<scope>provided</scope>添加到依赖项中,这应该可以解决您的tomcat问题。

重要编辑:我已经检查了日志,看起来您甚至不需要在您的widgetset的类路径中。 vaadin-mave-plugin使用它来编辑幕后的

[INFO] --- vaadin-maven-plugin:8.1.0:compile (default) @ test ---
[INFO] Using com.vaadin:vaadin-client-compiler version 8.1.0
[INFO] Compiling module MyCustomWidgetSet
[INFO]    Computing all possible rebind results for 'com.vaadin.client.metadata.ConnectorBundleLoader'
...

删除后,一切都按预期进行。不完全确定,但有可能只需要certain add-ons or the vaadin-maven-plugin。到目前为止我不需要写任何东西,所以也许实际需要它的人可以提供更多的洞察力。

4)您还可以根据相同的docs建议删除vaadin-client-compiled