师兄的源代码可以顺利执行并install,我又核对了一遍,发现一个小不同,product的父级pom我没有去掉<build>配置,去掉之后可以正常package和install了.
没有去掉<build>之前,单独对common模块执行package和install的命令同样报错:
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M3:repackage (default) on project common: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M3:repackage failed: Unable to find main class -> [Help 1]
按照提示在mvn使用-X的参数(mvn -X install),报错:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M3:repackage (default) on project common: Execution default of goal org.
springframework.boot:spring-boot-maven-plugin:2.0.0.M3:repackage failed: Unable to find main class -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M3:repackage (default) o
n project common: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M3:repackage failed: Unable to find main class
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M3:repackage fai
led: Unable to find main class
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalStateException: Unable to find main class
at org.springframework.boot.loader.tools.Repackager.buildManifest(Repackager.java:328)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:251)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:244)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:189)
at org.springframework.boot.maven.RepackageMojo.repackage(RepackageMojo.java:218)
at org.springframework.boot.maven.RepackageMojo.execute(RepackageMojo.java:205)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
[ERROR]
现在去掉<build>之后以上报错已消除.
但还是有点问题:
ps.其他部分确认代码,pom文件,版本,环境均相同,
1.我的代码在拆分之后,执行server模块的启动类时报错
"错误: 找不到或无法加载主类 com.imooc.product.ProductApplication"
网上搜索说执行 "mvn compile"命令即可,我执行后成功运行了ProductApplication启动类,再执行mvn clean后,启动会再次报错。
应该还是maven的问题,对maven还是不熟悉
2.另外执行idea的Build Project,依然会在message部分报一些找不到的错误(不影响程序运行)