1

I'm trying to package my webapp in a fat jar in order to be executed with java -jar my-app.jar. Everything works when I do mvn spring-boot:run but when I try to run the packaged jar with:

$ mvn clean package
$ java -jar target/my-app.jar

Spring Boot logo is shown but afer 3 or 4 seconds, it stops, without start any server.

This is my pom.xml:

<?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>com.digitalmenu</groupId>
    <artifactId>services</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jooq</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

EDITED

After enable logs, I see this error:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServlet ContainerException: Unable to start embedded Tomcat

Error creating bean with name 'jerseyConfig' defined in URL...

I have a class JserseyConfig...

I have tried this but still not working...

Héctor
  • 24,444
  • 35
  • 132
  • 243
  • When the app starts via "java -jar my.file.jar" then spring should have done a good job and maven too. The error must be in your java code?! – Matthias Dec 27 '16 at 21:12
  • The POM looks more or less fine except for `repackage` [missing](http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html). What does the log say? – lexicore Dec 27 '16 at 21:22
  • @lexicore No logs. I mean, it's like when server is started when after 3 seconds, it stops, prompt is shown, nothing happens. I have edited the question – Héctor Dec 27 '16 at 21:30
  • 1
    have you enabled debug (or even trace) level on the loggers? If not, please enable and try again, see if something more is logged. – Evil Toad Dec 27 '16 at 22:20
  • Start your app with `--debug` or `--trace` to get debug/trace output. – M. Deinum Dec 28 '16 at 07:30
  • Everything works when I run it with Maven. Problem is when I try to run it with `java -jar`. It starts and after 3 seconds, it stops. How can debug that? – Héctor Dec 28 '16 at 08:31
  • How about a [thread dump](http://stackoverflow.com/a/14119817/521799) of your JVM and post the blocking thread here? – Lukas Eder Dec 28 '16 at 13:02

1 Answers1

1

Finally, I found the answer! Thanks to the comment of the OP in this question's accepted answer.

I was registering the Jersey resources with:

packages("com.myapp.resources");

Registering each one individually everything works:

register(Res1.class);
register(Res2.class);
...
Community
  • 1
  • 1
Héctor
  • 24,444
  • 35
  • 132
  • 243