Swagger-codegen: Spring MVC - mvn package leads to "no main manifest attribute"

Created on 9 Mar 2016  路  8Comments  路  Source: swagger-api/swagger-codegen

Hi,

I have a Spring MVC server generated using Swagger.. And normally, to start it we use mvn jetty:run.. But I'd like to create a JAR file that I can launch afterwards.. So, to do that, I use the command mvn package and it creates correctly the JAR file in the target folder.

But when I try to start it using the command java -jar swagger-spring-mvc-server-1.0.0.jar, I get this error: no main manifest attribute, in swagger-spring-mvc-server-1.0.0.jar.

If I'm right, this problem happens because the Main.class is missing.. But I didn't find any main classes in the generated code.

Does anyone knows if I'm doing something wrong?? Or if there's another way to get the JAR file?
Thanks

Bug Spring help wanted

Most helpful comment

You can try this :
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

All 8 comments

Hi again,

I'm coming back here because I spend some time searching for building Spring-MVC using Maven..

So, from what I saw, a Web application doesn't have a main class and therefore should be compiled as a WAR file, not a JAR. Is it right??

If yes, then we need to update the pom.xml file.. I can have a look at that.

Hi again,

I was able to build the war file instead of the jar file.. But I still have the same problem no main manifest attribute, in swagger-spring-mvc-server-1.0..

Does anyone knows how to fix this problem??

Thanks

Hi @glederrey, as for as I know, you need to deploy the war file to a web container (web server, application server) to run it. Popular web containers includes Tomcat, WildFly and Glassfish. Jetty is an embeddable web server which is usually used to run Java web application in development (e.g. via the mvn jetty:run command which is a maven plugin to run jetty to host your Java web application).

Running a war file via java -jar is possible via, for example, adding jetty as a dependency and calling jetty's start-server method in the main entry class. However, I believe that is not the usual case for Java web apps, unless for standalone apps like Jenkins.

Hi @xhh,
From what I read on Internet (I'm not an expert in Java Spring-MVC), it's possible to build a WAR file with Spring-MVC and run it just using java -jar.. But in order to do this, we need a main function.. And we don't have it in the current version of generated Spring-MVC..

So, I tried adding the spring-boot-server and it did not work.. I will continue to dig on this problem and propose you something once I've found a solution..

In the mean time, if someone knows how to do this, I'd be happy to know..

did anyone find solution to this problem ?

You can try this :
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

@glederrey Maybe you were looking for this:
https://mvnrepository.com/artifact/io.swagger/swagger-codegen-cli/2.3.1
I got the same error message, then I noticed that I went for the wrong package.

@wing328 maybe you should close this Issue since its opener has not marked @glederrey answer as solving his problem. Although @glederrey answer has solved the problem here described at least for me.

Was this page helpful?
0 / 5 - 0 ratings