0

I'm using this little project to start my own project.

It is working fine until I add this dependency to the POM:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>  

Then I receive this error:

Failed to scan [file:/C:/Users/02221224710/.m2/repository/com/sun/xml/bind/jaxb-impl/2.3.0.1/jaxb-core.jar] from classloader hierarchy

    java.io.FileNotFoundException: C:\Users\02221224710\.m2\repository\com\sun\xml\bind\jaxb-impl\2.3.0.1\jaxb-core.jar (O sistema não pode encontrar o arquivo especificado)
        at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_161]
        at java.util.zip.ZipFile.<init>(Unknown Source) ~[na:1.8.0_161]
        at java.util.zip.ZipFile.<init>(Unknown Source) ~[na:1.8.0_161]
        at java.util.jar.JarFile.<init>(Unknown Source) ~[na:1.8.0_161]
        at java.util.jar.JarFile.<init>(Unknown Source) ~[na:1.8.0_161]
        at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:164) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:65) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49) ~[tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:374) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:309) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.tomcat.util.scan.StandardJarScanner.doScanClassPath(StandardJarScanner.java:266) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:229) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [tomcat-embed-jasper-9.0.19.jar:9.0.19]
        at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [tomcat-embed-jasper-9.0.19.jar:9.0.19]
        at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:83) [tomcat-embed-jasper-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5139) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0_161]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at java.util.concurrent.AbstractExecutorService.submit(Unknown Source) [na:1.8.0_161]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0_161]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at java.util.concurrent.AbstractExecutorService.submit(Unknown Source) [na:1.8.0_161]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:455) [tomcat-embed-core-9.0.19.jar:9.0.19]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:106) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:427) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:180) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
        at com.hellokoding.springboot.view.Application.main(Application.java:17) [classes/:na]

Actually I started to face this problem in a working old project after some Spring version upgrade. I can't remember the old version number but I can downgrade if someone wants to confirm. My code was working perfectly before the uprade so I decided to start from zero again and use the small project above to check what was happen then I started to copy all my dependencies one by one from the old project to the new working one until I paste the OAuth2 dependency so the new fresh working project gives me the same error that my old project (related to jaxb-impl\2.3.0.1\jaxb-core.jar not be found).

How can I use spring-cloud-starter-oauth2 in a Tomcat JSP-based project now?

This is my problematic POM:

<?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>br.com.cmabreu</groupId>
    <artifactId>atlas-2</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>atlas-2</name>
    <description>Geoportal Atlas</description>  

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
        <maven.test.skip>true</maven.test.skip>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>   


        <!-- ************************************************************** -->
        <!--                     TROBLE HERE !!!                            -->
        <!-- ************************************************************** -->     
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>       
        <!-- ************************************************************** -->     
        <!-- ************************************************************** -->     


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>    

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>    
</project>

EDIT Sorry, my IDE is in pt_BR. O sistema não pode encontrar o arquivo especificado means The system cannot find the specified file

EDIT 2 PLEASE the link above didn't solve my problem. Disable the JAR scanner makes my application starts to complain about JSTL. I've noticed its actualy WORKS although the missing JAXB error but disabling the scanner makes it stop to work.

All these tutorials shows basicaly the same thing, including the Tomcat, Jasper, and so on and all of them are working but they tells nothing aboout put the OAuth dependency that makes ALL of then shows the SAME error.

https://www.mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/

https://htr3n.github.io/2018/12/jsp-spring-boot/

https://www.mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/

https://hellokoding.com/spring-boot-hello-world-example-with-jsp/

I can't believe no one is using Spring Boot + JSP + OAuth...

Magno C
  • 1,448
  • 2
  • 21
  • 43
  • @ThomasAndolf yes. Isn't there. Also forced a Maven clean / package / install. The file was not downloaded anyway. Maven tells me the same: can't find the file and not download it. Also deleted the entire repository and refresh all the project. You can try by yourself: just checkout the project from the link I gave and add the OAuth2 dependency. It is a very tinny project don't worry. – Magno C Jun 13 '19 at 23:05
  • When running from Spring Tool Suite or building from command line (mvn). – Magno C Jun 14 '19 at 00:49
  • 1
    i checked it out and built it using mvn clean install after adding the dependency and i did not get any error. It built fine. – Toerktumlare Jun 14 '19 at 01:00
  • Hum. I think I must double check my environment... Can you run and access the `hello` page ? – Magno C Jun 14 '19 at 01:16
  • no because i don\t have a tomcat installed to deploy on and your projects are not setup as correct fat runnable spring boot jars. – Toerktumlare Jun 14 '19 at 02:10
  • 1
    What are you talking about? Just checkout the project, `mvn install` in same folder the POM file is and do a `java -jar springboot-jsp-helloworld-1.0-SNAPSHOT.war`. – Magno C Jun 14 '19 at 03:07
  • Possible duplicate of [Spring Boot Embedded Tomcat Dependency Throws Exception On Startup](https://stackoverflow.com/questions/43328022/spring-boot-embedded-tomcat-dependency-throws-exception-on-startup) – dur Jun 14 '19 at 08:26
  • Okey, first of all, what im talking about is that if you look you can see that it is a WAR file... not a JAR file. Read up on what a war file is, https://en.wikipedia.org/wiki/WAR_(file_format) it is a Web Application Resource (WAR). So what does that mean, it means that it is a file that is meant to be deployed into a server (like tomcat). If you want to run this as a standalone application containing a server and a application you need to package this as a fat-jar and for that you need to use the spring boot maven plugin. If you have no idea what im talking about, start googling! – Toerktumlare Jun 14 '19 at 17:03
  • `that it is a WAR file` : have faith... it's Spring man. trust in me... it will run if you do what I said. `java -jar springboot-jsp-helloworld-1.0-SNAPSHOT.war` WILL run. – Magno C Jun 14 '19 at 17:20
  • @dur your comment makes sense. As Thomas said I ran the project in pure command line to prove him it will run as WAR and surprisely I don't see the related error with OAuth dependency. I'm curious because it doesn't work only if I add the OAuth dependency (inside STS for now). The link you pointed tells nothing about OAuth. – Magno C Jun 14 '19 at 17:44
  • @ThomasAndolf OP is using the Spring Boot Starter Parent, which contains the Spring Boot Maven plugin. However, as you could see in the stack trace, OP is using an embedded Tomcat. – dur Jun 14 '19 at 21:34
  • @MagnoC The link tells nothing about OAuth, because your problem is not an OAuth problem. It is an Tomcat problem. The OAuth dependency contains a dependency, which contains an TTL for jaxb-impl. – dur Jun 14 '19 at 21:40
  • @dur I understood the problem. Any sugestion? I can't extract nothing from the instructions you pointed. I don't know how to manage that in Spring stuff... I can't believe no one is facing this same problem. – Magno C Jun 15 '19 at 00:00
  • i missed the declaration of the spring-boot-maven plugin at the bottom. Your problem is the following. You have `provided` on your dependency `spring-boot-starter-tomcat` this will make maven assume that this dependency will be provided during runtime by the container running the application. So maven will not pack in tomcat in your jar. So when you start, it can not start any server because you have told it that it shouldn't be in the jar. Remove the scope and you can then magically start your server. – Toerktumlare Jun 15 '19 at 00:07
  • why can you start your server_ well because if you look into the `spring-boot-starter-web` dependencies pom you can see that it already pulls in tomcat for you. – Toerktumlare Jun 15 '19 at 00:10
  • @ThomasAndolf alright makes sense. I'll check this at my work. Monday I'll post the results. Thanks. – Magno C Jun 15 '19 at 00:24
  • @MagnoC To fix your problem, try https://stackoverflow.com/a/43280452/5277820 – dur Jun 15 '19 at 09:07
  • Thanks @dur. Are the Spring guys concerned about this? I'm not doing nothing special or different from the official ways to include OAuth2 security in a JSP based server ( Spring Boot is naturally Tomcat ). You can find thousands tutorials doing the same around. – Magno C Jun 15 '19 at 15:30
  • Hi @dur. After tests with the solution in the link you pointed, I edited my question again. Please see my **EDIT 2** – Magno C Jun 17 '19 at 13:11
  • @MagnoC Did you try `server.tomcat.additional-tld-skip-patterns=*.jar` or `((StandardJarScanner) context.getJarScanner()).setScanManifest(false);`? – dur Jun 17 '19 at 20:36
  • Using `server.tomcat.additional-tld-skip-patterns=*.jar` in `bootstrap.properties`... but isn't the same final result? – Magno C Jun 18 '19 at 10:43

0 Answers0