2017-05-10 162 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> 
相關問題