12

Maven build succeeded but when I trying to run it fails with:

Error: Could not find or load main class app.jar

I have in resources/META-INF/MANIFEST.MF with

Manifest-Version: 1.0
Main-Class: go.Application

All seems in place. What's wrong?

pom.xml

<build>
        <plugins>
             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <archive>
                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>

            </plugin>

        </plugins>
    </build>

UPDATE1

Same story when building jar artifact with IntelliJ.

UPDATE2

OK, I managed to run it but now I have :

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

UPDATE3

Got it working by adding to Application.java:

@Bean
        public EmbeddedServletContainerFactory servletContainer() {
            TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
            return factory;
        }
6
  • 1
    How do you start the application? Seems to me like the parameter -jar is missing when java is called. Commented Jan 21, 2015 at 10:08
  • when i add -jar it shows different error Unable to access jarfile Commented Jan 21, 2015 at 10:10
  • That sounds like your path is wrong. Are you in the correct directory? Commented Jan 21, 2015 at 10:16
  • Is this spring-boot? With spring-boot you don't need that maven jar config, nor do you need the bean you've created in your application.java. Commented Jan 21, 2015 at 16:39
  • I have the same question as Engineer Dollery. It seems like you are trying to run this as a spring boot app. If so then you need the spring-boot-maven-plugin with sets up all the required references in your jar. So Spring Boot? Commented Jan 22, 2015 at 4:32

1 Answer 1

4

Ok, So i was beating my head over this... I had the following:

/**
 * Main class.
 */
@SpringBootApplication
public class Application {

  /**
   * Main entry point for the application.
   *
   * @param args The args to pass in
   */
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

and all my dependencies were correct..

After an exhausive search, i found the following:

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application-executable-jar

Since i dont have the spring boot parent as my parent, I had to include the executions section in my plugin configuration like so:

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <mainClass>your.Application.fqdn.here</mainClass>
          <layout>ZIP</layout>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin> 

See the following for additional info:

http://docs.spring.io/spring-boot/docs/1.4.0.BUILD-SNAPSHOT/maven-plugin/usage.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.