"Go" Spring boot into jar package problem summary

Source: Internet
Author: User

Http://www.cnblogs.com/xingzc/p/5972488.html

1. Unable to find a single main class from the following candidates1.1, problem description

The following error message log appears in Maven build:

[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]
1.2. Log Analysis
Unable to find a single main class from the following candidates [com.hhly.InformationApplication, com.hhly.test.Application]// 不能从下面的候选类中找到单一的main类

1.3. Solutions

Looking at two classes and discovering that two classes do have a main method in two classes, remove an extra main method and leave the unique main method.

2, the jar does not have the main list attribute 2.1, the problem description

After producing the corresponding jar package, run the Spring boot program with a command,

-jar information-0.0.1-SNAPSHOT.jar
    • 1
    • 1

2.2, problem analysis

Find data found as Meta-inf/manifest in the last generated jar package. MF file, the main function information is not set. Conjecture is the problem set by Pom.xml, compared to the settings on the web, found that most configurations are as follows:

    <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> Span class= "Hljs-tag" ><executions> < execution> <goals> <goal>repackage</ goal> </goals> </execution> </executions> </plugin> </ plugins> </BUILD>    

Compared to their own settings found: They also wrapped a pluginmanagement label outside the label.

2.3. Solutions

Remove the Pluginmanagement label.

3, property ' sqlsessionfactory ' or ' sqlsessiontemplate ' is required3.1, problem description

First, with Maven clean, then the MAVEN build, the following error occurs when you execute the main function, and the detailed log is as follows:

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
3.2, problem analysis

The same code, when the project is updated with ALT + F5, and then the MAVEN build builds the jar package, the final execution of the main will not be an error.

3.3. Solutions

Adjust the packing order as follows:
1, Alt + F5
2. Maven Build

4 Spring-boot-maven-plugin Plug -in function 

The "Org.springframework.boot:spring-boot-maven-plugin" plugin was added to the POM file. After the plugin is added, when the MVN package is run, it is packaged as a JAR file that can be run directly, and can be run directly using the "Java-jar" command. This simplifies the deployment of the application to a great extent, and only installs the JRE to run it.

You can specify whether a jar or war is generated in the POM.

<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>

You can also specify the class to execute, and if not specified, spring will find the class that has this " public static void main(String[] args) " method as an executable class.

If you want to specify, you can use the following two methods:

1, if your pom is inherited spring-boot-starter-parent, only need the following designation on the line.

<properties>    <!-- The main class to start by executing java -jar -->    <start-class>com.mycorp.starter.HelloWorldApplication</start-class></properties>
2, if your pom is not inheritedSpring-boot-starter-parent, the following designation is required.

    <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.html
Http://stackoverflow.com/questions/23217002/how-do-i-tell-spring-boot-which-main-class-to-use-for-the-executable-jar
Http://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html
Http://udn.yyuap.com/doc/Spring-Boot-Reference-Guide/III.%20Using%20Spring%20Boot/13.1.4.%20Using%20the% 20spring%20boot%20maven%20plugin.html
http://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/#listing1

"Go" Spring boot into jar package problem summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.