-1

I'm trying to make an executable jar of a spring application. However whenever I try to run it using java -jar jar file, I get the error:

Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

I'm running using

mvn clean compile assembly:single

When I use Eclipse to run the server, it runs fine. Here is my pom file:

<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>aopricing</groupId>
<artifactId>aopricing</artifactId>
<version>0.0.1-SNAPSHOT</version>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>


<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>

</properties>


<dependencies>



    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.3.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>


</dependencies>

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

        </plugin>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source />
                <target />
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>server.Application</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>

    </plugins>
</build>

I know this has been answered on other threads, but none of them worked for me, I tried creating an executable jar file from eclipse, but that had other issues.

spearmunkie
  • 21
  • 1
  • 7
  • You did try things ? Like what ? Tell us so that we dont repeat them. Did you read [this](http://stackoverflow.com/questions/21783391/spring-boot-unable-to-start-embeddedwebapplicationcontext-due-to-missing-embedd) ? And [this](http://stackoverflow.com/questions/34022580/spring-boot-error-unable-to-start-embeddedwebapplicationcontext-due-to-missing) ? What about [this](https://github.com/spring-projects/spring-boot/issues/861) one ? I have no idea what these things are but I know setting `@EnableAutoConfiguration` solved it for a lot of people. We are not a Googling service, use it urself. – UDKOX May 15 '16 at 02:31
  • @UDKOX already tried all of those – spearmunkie May 15 '16 at 02:34
  • You tried those ? Which ones ? Add them to the post. We won't try to help if you don't tell us what you already tried. `I tried creating an executable jar file from eclipse, but that had other issues.` What issues ? Did you try to fix them ? Invest some time before asking. – UDKOX May 15 '16 at 02:37
  • Are you aware you're using Spring Boot? – kryger May 15 '16 at 20:27
  • @kryger Yes, from a different answer, running mvn sprin-boot:run ran the web server. I had to change my java version from 1.8 to 1.7 due to some of my code. I want to package it into a jar so that it can run on a different server without any additional packages. – spearmunkie May 16 '16 at 02:42

1 Answers1

0

I will firstly run the command from command line to verify if the application can run from command line.

mvn spring-boot:run

Normally, I build the fat jar by running

mvn clean install

And then take the .jar file from #WORKING_DIR#/target folder. Hope this can shed some light for your debugging.

DoT
  • 89
  • 4
  • This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/12361505) – Ro Yo Mi May 16 '16 at 00:52
  • 1
    Thank Ro Yo Mi for your information. I haven posted my answers to StackOverflow recently and hence don't know much about the rule. – DoT May 16 '16 at 03:43