Stephen Chang
Stephen Chang

Reputation: 29

"Unable to read TLD from JAR file" when run spring boot app on heroku

I wrote an springboot app running at Heroku. When I run locally with maven spring-boot:run everthing is ok.

But when I deploy the app to Heroku, the page show error:

There was an unexpected error (type=Internal Server Error, status=500).
/WEB-INF/jsp/login.jsp (line: 3, column: 0) /WEB-INF/jsp/common.jsp (line: 3, column: 64) Unable to read TLD "META-INF/spring.tld" from JAR file "jar:file:/app/target/slog-1.0-SNAPSHOT.jar!/lib/spring-webmvc-4.0.7.RELEASE.jar": java.io.IOException: Unable to open root Jar file 'jar:file:/app/target/slog-1.0-SNAPSHOT.jar'

And I run the jar locally with "java -jar target/*.jar" have the same error.

this is my pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>ort.stv</groupId>
<artifactId>slog</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Spring Boot Blog System</name>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
    </dependency>


    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- JSR303 BeanValidator -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>


    <!-- GENERAL UTILS begin -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.3.2</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
    <!-- GENERAL UTILS end -->


    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901-1.jdbc4</version>
        <classifier />
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.scala-lang</groupId>-->
        <!--<artifactId>scala-library</artifactId>-->
        <!--<version>2.10.4</version>-->
    <!--</dependency>-->
</dependencies>

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

Upvotes: 2

Views: 1797

Answers (2)

Stephen Chang
Stephen Chang

Reputation: 29

I found a better way to deploy spring boot app to heroku.

first change maven package to war.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warSourceExcludes>WEB-INF/lib/log4j-${log4j.version}.jar</warSourceExcludes>
            </configuration>
        </plugin>

then change Procfile to web: java $JAVA_OPTS -jar target/*.war .

solved :D.

Upvotes: 0

Scott
Scott

Reputation: 1550

There is a known limitation in Spring Boot and an open issue related to using JSPs with embedded containers. Long story short, it's not currently supported. However, the Spring Boot reference documentation links to a GitHub example project they claim gets it working.

Upvotes: 2

Related Questions