2017-05-10 161 views
1

我使用Maven“mvn clean package”打包了一个spring引导服务,并且我成功地能够创建该jar。但是,当我使用下面的命令从命令行运行它:“Java的罐子\目标\ noentenimnininc-0.0.1-SNAPSHOT.jar”我得到下面的错误::从命令行运行Spring Boot应用程序时出错

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

这是主类

@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()); 
    }  
} 

,一切工作正常,从Eclipse中运行类 - >运行方式 - > Java的应用项目

这里该模块的pom.xml中:

<?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> 
+0

是否配置弹簧引导Maven的插件生成相应的可执行的JAR – Tome

+0

检查这个帖子http://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute –

回答

2

只需添加到您的pom.xml,使春季启动Maven插件重新打包的JAR成可执行一个:

<build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
相关问题