请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

product项目无法mvn clean install -Dmaven.test.skip=true成功

项目拆分完成后,与讲师源码进行一一对比,确保配置,版本,环境等完全相同,并且product项目也可以正常启动,但在执行打包命令时(mvn clean install -Dmaven.test.skip=true),无法成功打包,报错:

[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:spr
ing-boot-maven-plugin:2.0.0.M3:repackage failed: Unable to find main class -> [Help 1]

[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :common

并且在使用Build Project时,总是报错:
Error:(3, 32) java: 程序包com.imooc.product.common不存在
但我的项目已经可以执行了,并且访问"/msg"也成功了,在代码编辑窗口,相关代码也没有报错标识,没有找到合适的解决方案,求助
图片描述
图片描述
ps.已经挨个核对product项目的所有pom配置是与课程源码相同的了

正在回答

3回答

“与讲师源码进行一一对比,确保配置,版本,环境等完全相同”说明是代码不一样吧,你用我的源码tag=5-9,可以运行成功吗

0 回复 有任何疑惑可以回复我~
  • 提问者 ArchGeass #1
    已确认是product的父级pom我没有去掉<build>配置,去掉之后可以正常package和install了.
    ps.其他部分确认代码,pom文件,版本,环境均相同,
    1.我的代码在拆分之后,执行server模块的启动类时报错
    "错误: 找不到或无法加载主类 com.imooc.product.ProductApplication"
    网上搜索说执行 "mvn compile"命令即可,我执行后成功运行了ProductApplication启动类,再执行mvn clean后,启动会再次报错。
    应该还是maven的问题,对maven还是不熟悉
    2.另外执行idea的Build Project,依然会在message部分报一些找不到的错误(不影响程序运行)
    回复 有任何疑惑可以回复我~ 2019-04-09 16:25:57
廖师兄 2019-04-11 00:21:27

看图吧

https://img1.sycdn.imooc.com//szimg/5cae17f500017e9b28801800.jpg

0 回复 有任何疑惑可以回复我~
提问者 ArchGeass 2019-04-09 16:24:52

师兄的源代码可以顺利执行并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部分报一些找不到的错误(不影响程序运行)

https://img1.sycdn.imooc.com//szimg/5cac56c50001b48919201040.jpg

0 回复 有任何疑惑可以回复我~
  • 提问者 ArchGeass #1
    pom的<build>是指:
    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    回复 有任何疑惑可以回复我~ 2019-04-09 16:27:15
  • 在项目跟目录,命令行里mvn clean package,成功。idea里不行,肯定是idea有问题,从截图里看,是jar包没下载成功。你把代码push到git吧,我帮你看看
    回复 有任何疑惑可以回复我~ 2019-04-10 00:44:24
  • 提问者 ArchGeass 回复 廖师兄 #3
    麻烦师兄了:
    https://git.imooc.com/ArchGeass/SpringCloud_learn.git
    回复 有任何疑惑可以回复我~ 2019-04-10 13:18:00
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信