Java 从命令行运行Spring启动应用程序时出错
我已经使用Maven“mvn clean package”打包了一个spring引导服务,并且成功地创建了jar。但是,当我使用下面的命令从命令行运行它时:“java-jar\target\noenteinninc-0.0.1-SNAPSHOT.jar”我得到下面的错误:Java 从命令行运行Spring启动应用程序时出错,java,spring,eclipse,maven,spring-boot,Java,Spring,Eclipse,Maven,Spring Boot,我已经使用Maven“mvn clean package”打包了一个spring引导服务,并且成功地创建了jar。但是,当我使用下面的命令从命令行运行它时:“java-jar\target\noenteinninc-0.0.1-SNAPSHOT.jar”我得到下面的错误: no main manifest attribute, in noentenimnininc-0.0.1-SNAPSHOT.jar 这是主课 @SpringBootApplication @Import({SecurityC
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());
}
}
@springboot应用程序
@导入({SecurityConfig.class})
公共类NoEventInNicIncApplication实现CommandLineRunner{
/**应用程序记录器*/
私有静态最终记录器LOG=LoggerFactory.getLogger(noenteimnicincapplication.class);
@自动连线
私人用户服务;
@值(${webmaster.username}”)
私有字符串webmasterUsername;
@值(${webmaster.password}”)
私有字符串webmasterPassword;
@值(${webmaster.email}”)
私人字符串网站管理员电子邮件;
公共静态void main(字符串[]args){
运行(noenteninicinapplication.class,args);
}
@凌驾
公共无效运行(字符串…参数)引发异常{
User User=UserUtils.createBasicUser(webmasterUsername,webmasterEmail);
user.setPassword(webmasterPassword);
Set userRoles=new HashSet();
添加(新用户角色(用户,新角色(RolesEnum.ADMIN));
debug(“使用用户名{}创建用户”,user.getUsername());
createUser(用户,PlansEnum.PRO,用户角色);
LOG.info(“用户{}已创建”,User.getUsername());
}
}
从Eclipse->runas->javaappapplication运行这个类,一切都很好
下面是本模块的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>
4.0.0
com.noenteinnicinc.iot.web
尼克公司网站
0.0.1-快照
罐子
org.springframework.boot
spring启动程序父级
1.5.3.1发布
UTF-8
1.8
org.springframework.boot
弹簧靴起动器执行器
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动装置
org.springframework.boot
弹簧起动试验
测试
uk.co.jemos.podam
波达姆
7.0.5.1发布
测试
com.noenteinnicinc.iot.core
镍业公司核心
0.0.1-快照
回写
回归经典
org.webjars
独自创立
3.3.7-1
org.webjars
jquery
3.2.0
org.thymeleaf.extras
thymeleaf-extras-springsecurity4
只需将其添加到您的pom.xml
,这样Spring Boot Maven插件就可以将您的JAR重新打包为可执行的JAR:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
org.springframework.boot
springbootmaven插件
您是否配置了spring boot maven插件来生成相应的可执行文件