1
votes

I have packaged a spring boot service using Maven "mvn clean package" and I am successfully able to create the jar. But when I run it from command line using below command : "java -jar \target\noentenimnininc-0.0.1-SNAPSHOT.jar" I am getting below error ::

no main manifest attribute, in noentenimnininc-0.0.1-SNAPSHOT.jar

this is the main class

@SpringBootApplication
@Import({SecurityConfig.class })
public class NoEnTenimNiCincApplication  implements CommandLineRunner {

    /** The application logger */
    private static final Logger LOG = LoggerFactory.getLogger(NoEnTenimNiCincApplication.class);

    @Autowired
    private UserService userService;

    @Value("${webmaster.username}")
    private String webmasterUsername;

    @Value("${webmaster.password}")
    private String webmasterPassword;

    @Value("${webmaster.email}")
    private String webmasterEmail;

    public static void main(String[] args) {
        SpringApplication.run(NoEnTenimNiCincApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {

        User user = UserUtils.createBasicUser(webmasterUsername, webmasterEmail);
        user.setPassword(webmasterPassword);
        Set<UserRole> userRoles = new HashSet<>();
        userRoles.add(new UserRole(user, new Role(RolesEnum.ADMIN)));
        LOG.debug("Creating user with username {}", user.getUsername());
        userService.createUser(user, PlansEnum.PRO, userRoles);
        LOG.info("User {} created", user.getUsername());
    }    
}

and everything works fine running the class from Eclipse -> Run As -> Java Appplication

Here the pom.xml of this module:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.noentenimnicinc.iot.web</groupId>
  <artifactId>nicinc-web</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
  </parent>

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

  <dependencies>
        <!-- Spring Boot dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>uk.co.jemos.podam</groupId>
            <artifactId>podam</artifactId>
            <version>7.0.5.RELEASE</version>
            <scope>test</scope>
        </dependency>

        <!-- nicinc-core dependencies -->
        <dependency>
             <groupId>com.noentenimnicinc.iot.core</groupId>
            <artifactId>nicinc-core</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <!-- Logging dependencies -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>

        <!-- Webjars for JQuery and Bootstrap -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7-1</version>
        </dependency> 
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.2.0</version>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
            <!-- <version>3.0.2.RELEASE</version> -->
        </dependency>


   </dependencies>


</project>
1
Did you configure the spring-boot-maven-plugin to generate the appropriate executable JARTome

1 Answers

3
votes

Just add this to your pom.xml, so that Spring Boot Maven Plugin repackages your JAR into an executable one:

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