maven build时出现如下错误提示日志:css
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.5.RELEASE:repackage (default) on project information: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.5.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.hhly.InformationApplication, com.hhly.test.Application] -> [Help 1]
Unable to find a single main class from the following candidates [com.hhly.InformationApplication, com.hhly.test.Application] // 不能从下面的候选类中找到单一的main类
查看着两个类,发现两个类中确实两个类中均有一个main方法,去掉一个多余的main方法,保留惟一的main方法。html
生产对应的jar包以后,经过一下命令运行spring boot程序,java
java -jar information-0.0.1-SNAPSHOT.jar
查找资料发现为最后生成的jar包中的META-INF/MANIFEST.MF文件,没有设置主函数信息。猜测是pom.xml设置的问题,比对网上的设置,发现多数配置都是以下:spring
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <maimClass>com.hhly.InformationApplication</maimClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
比对本身的设置发现:本身在标签外面还包了一个 pluginManagement标签。sql
去掉pluginManagement标签。apache
首先经过maven clean,而后再执行maven build,在执行main函数时会出现下面错误,详细日志以下:session
2016-09-09 18:29:43.419 WARN 37076 --- [ost-startStop-1] o.s.b.f.s.DefaultListableBeanFactory : Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\neon-workspace\information \target\classes\com\hhly\dao\UserMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
一样的代码,在经过Alt + F5更新项目,而后maven build生成jar包,最后执行的main的时候也就不会报错。app
调整打包顺序以下:
一、Alt + F5
二、maven buildmaven
POM 文件中添加了“org.springframework.boot:spring-boot-maven-plugin”插件。在添加了该插件以后,当运行“mvn package”进行打包时,会打包成一个能够直接运行的 JAR 文件,使用“Java -jar”命令就能够直接运行。这在很大程度上简化了应用的部署,只须要安装了 JRE 就能够运行。ide
能够在POM中,指定生成 的是Jar仍是War。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- ... -->
<packaging>jar</packaging>
<!-- ... -->
</project>
你还能够指定要执行的类,若是不指定的话,Spring会找有这个【public static void main(String[] args)
】方法的类,当作可执行的类。
若是你想指定的话,能够用下面两个方法:
1,若是你的POM是继承spring-boot-starter-parent的话,只须要下面的指定就行。
<properties> <!-- The main class to start by executing java -jar --> <start-class>com.mycorp.starter.HelloWorldApplication</start-class> </properties>
2,若是你的POM不是继承
spring-boot-starter-parent的话,须要下面的指定。
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.3.5.RELEASE</version> <configuration> <mainClass>${start-class}</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
from:
http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.htmlhttp://stackoverflow.com/questions/23217002/how-do-i-tell-spring-boot-which-main-class-to-use-for-the-executable-jarhttp://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.htmlhttp://udn.yyuap.com/doc/Spring-Boot-Reference-Guide/III.%20Using%20Spring%20Boot/13.1.4.%20Using%20the%20Spring%20Boot%20Maven%20plugin.htmlhttp://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/#listing1