{"id":238,"date":"2024-06-16T17:31:50","date_gmt":"2024-06-16T09:31:50","guid":{"rendered":"https:\/\/blog.jishuge.cn\/?p=238"},"modified":"2024-06-16T17:31:50","modified_gmt":"2024-06-16T09:31:50","slug":"springboot%e9%a1%b9%e7%9b%ae%e6%89%93%e5%8c%85%e5%87%ba%e7%8e%b0unable-to-find-main-class","status":"publish","type":"post","link":"https:\/\/blog.jishuge.cn\/?p=238","title":{"rendered":"SpringBoot\u9879\u76ee\u6253\u5305\u51fa\u73b0Unable to find main class"},"content":{"rendered":"\n<p>\u5982\u679c\u4f60\u5728\u5c1d\u8bd5\u5355\u72ec\u6253\u5305\u4e00\u4e2aSpring Boot\u6a21\u5757\u65f6\u9047\u5230\u201cUnable to find main class\u201d\u7684\u9519\u8bef\uff0c\u8fd9\u901a\u5e38\u610f\u5473\u7740Maven\u6216Gradle\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u627e\u5230\u5e26\u6709@SpringBootApplication\u6ce8\u89e3\u7684\u4e3b\u7c7b\uff0c\u5373\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002\u4ee5\u4e0b\u662f\u51e0\u4e2a\u53ef\u80fd\u7684\u539f\u56e0\u53ca\u76f8\u5e94\u7684\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"> \u539f\u56e0\u4e0e\u89e3\u51b3\u65b9\u6cd5\uff1a<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\u3001\u7f3a\u5c11\u4e3b\u542f\u52a8\u7c7b<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u68c0\u67e5\u6a21\u5757\u5185\u662f\u5426\u786e\u5b9e\u5b58\u5728\u4e00\u4e2a\u5e26\u6709@SpringBootApplication\u6ce8\u89e3\u7684\u7c7b\u3002<\/li>\n\n\n\n<li>\u786e\u8ba4\u8be5\u7c7b\u5305\u542b\u4e00\u4e2a\u516c\u6709\u7684static void main(String[] args)\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c\u3001\u4e3b\u542f\u52a8\u7c7b\u547d\u540d\u6216\u4f4d\u7f6e\u9519\u8bef<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u786e\u8ba4\u4e3b\u542f\u52a8\u7c7b\u7684\u540d\u79f0\u548c\u5305\u8def\u5f84\u662f\u5426\u4e0e\u4f60\u5728\u6784\u5efa\u914d\u7f6e\u4e2d\u6307\u5b9a\u7684\u4e00\u81f4<\/li>\n\n\n\n<li>\u4e3b\u542f\u52a8\u7c7b\u5e94\u4f4d\u4e8e\u6a21\u5757\u7684\u5408\u7406\u5305\u8def\u5f84\u4e0b\uff0c\u901a\u5e38\u76f4\u63a5\u5728\u6a21\u5757\u7684\u4e3b\u8981\u6e90\u4ee3\u7801\u76ee\u5f55\u4e2d\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e09\u3001\u6784\u5efa\u63d2\u4ef6\u914d\u7f6e\u95ee\u9898<\/h3>\n\n\n\n<p>\u5728\u6a21\u5757\u7684pom.xml\u6216build.gradle\u4e2d\u68c0\u67e5spring-boot-maven-plugin\u6216bootJar\u7684\u914d\u7f6e\u3002<\/p>\n\n\n\n<p>\u786e\u4fdd\u6b63\u786e\u8bbe\u7f6e\u4e86mainClass\u5c5e\u6027\uff0c\u6307\u5411\u4f60\u7684\u4e3b\u542f\u52a8\u7c7b\u7684\u5168\u9650\u5b9a\u540d\uff0c\u4f8b\u5982<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">       &lt;build>\n           &lt;plugins>\n               &lt;plugin>\n                   &lt;groupId>org.springframework.boot&lt;\/groupId>\n                   &lt;artifactId>spring-boot-maven-plugin&lt;\/artifactId>\n                   &lt;configuration>\n                       &lt;mainClass>com.example.module.YourMainApplication&lt;\/mainClass>\n                   &lt;\/configuration>\n               &lt;\/plugin>\n           &lt;\/plugins>\n       &lt;\/build>\n       <\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"groovy\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">bootJar {\n   mainClassName = 'com.example.module.YourMainApplication'\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u56db\u3001\u6a21\u5757\u4f9d\u8d56\u95ee\u9898\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u68c0\u67e5\u662f\u5426\u6709\u672a\u89e3\u51b3\u7684\u4f9d\u8d56\u95ee\u9898\uff0c\u7279\u522b\u662f\u90a3\u4e9b\u53ef\u80fd\u5f71\u54cd\u5230\u4e3b\u542f\u52a8\u7c7b\u52a0\u8f7d\u7684\u4f9d\u8d56\u3002<\/li>\n\n\n\n<li>\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u90fd\u5df2\u6b63\u786e\u58f0\u660e\u5e76\u53ef\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e94\u3001\u6e05\u7406\u4e0e\u91cd\u5efa\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6267\u884cmvn clean install\u6216gradlew clean build\u6765\u6e05\u9664\u65e7\u7684\u6784\u5efa\u7ed3\u679c\u5e76\u91cd\u65b0\u6784\u5efa\u3002<\/li>\n\n\n\n<li>\u6709\u65f6\u65e7\u7684\u6784\u5efa\u5de5\u4ef6\u6216\u7f13\u5b58\u6570\u636e\u53ef\u80fd\u4f1a\u5e72\u6270\u65b0\u7684\u6784\u5efa\u8fc7\u7a0b\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5e94\u8be5\u80fd\u591f\u5b9a\u4f4d\u5e76\u89e3\u51b3\u627e\u4e0d\u5230\u4e3b\u7c7b\u7684\u95ee\u9898\uff0c\u4ece\u800c\u6210\u529f\u5730\u5355\u72ec\u6253\u5305\u4f60\u7684Spring Boot\u6a21\u5757\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u5728\u5c1d\u8bd5\u5355\u72ec\u6253\u5305\u4e00\u4e2aSpring Boot\u6a21\u5757\u65f6\u9047\u5230\u201cUnable to find main class\u201d\u7684\u9519\u8bef.<\/p>\n","protected":false},"author":1,"featured_media":239,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[12,25],"class_list":["post-238","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-springboot","tag-25"],"_links":{"self":[{"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=238"}],"version-history":[{"count":1,"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=\/wp\/v2\/posts\/238\/revisions"}],"predecessor-version":[{"id":240,"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=\/wp\/v2\/posts\/238\/revisions\/240"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=\/wp\/v2\/media\/239"}],"wp:attachment":[{"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jishuge.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}