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