龙空技术网

Windows环境Maven编译打包报错,Mac打包正常

极简架构 137

前言:

此刻看官们对“apache207”大约比较关心,小伙伴们都想要知道一些“apache207”的相关知识。那么小编在网络上汇集了一些有关“apache207””的相关内容,希望我们能喜欢,我们快快来学习一下吧!

#头条创作挑战赛# #maven#

Windows Maven报错(Mac打包正常):

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project xx-common-base: Compilation failure

Maven打包错误堆栈信息:

mvn clean package -X

-nowarn -target 1.8 -source 1.8 -encoding UTF-8 -bootclasspath C:\Program Files\Java\jdk1.8.0_251\jre/lib/rt.jar:C:\Program Files\Java\jdk1.8.0_251\jre/lib/jce.jar[DEBUG] incrementalBuildHelper#beforeRebuildExecution[INFO] Compiling 29 source files to D:\xxx\xxx-commons\xxx-common-base\target\classes致命错误: 在类路径或引导类路径中找不到程序包 java.lang[DEBUG] incrementalBuildHelper#afterRebuildExecution[INFO] -------------------------------------------------------------[ERROR] COMPILATION ERROR :[INFO] -------------------------------------------------------------[ERROR] An unknown compilation problem occurred[INFO] 1 error[INFO] ------------------------------------------------------------ -[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 2.275 s[INFO] Finished at: 2023-04-04T11:41:21+08:00[INFO] Final Memory: 16M/185M[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project xxx-common-base: Compilation failure[ERROR] An unknown compilation problem occurred[ERROR] -> [Help 1]org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project xxx-common-base: Compilation failureAn unknown compilation problem occurredat org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)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:307)at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)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)at org.codehaus.classworlds.Launcher.main(Launcher.java:47)Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failureAn unknown compilation problem occurredat org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1220)at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:187)at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)... 21 more[ERROR][ERROR][ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1]  finished with exit code 1
问题排查:

问题关键提示信息: 报java.lang包没找到,怀疑跟环境变量或Windows jdk路径有关

1.排查java环境变量=> 正常

2.怀疑跟Windows jdk路径相关 => 根因

问题原因

Windows环境Maven compiler插件路径问题

问题fix方案:

如下所示的配置很特殊:Windows 下使用分号(;)分隔,Linux/Mac 下使用冒号(:)分隔

修改后重新Maven打包正常,问题修复

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven.compiler.version}</version><configuration><source>${java.version}</source><target>${java.version}</target><encoding>UTF-8</encoding><!-- 不是maven推荐的方式,只是为了方便管理后台人员频繁开发的jar包 --><compilerArguments><extdirs>src\main\webapp\WEB-INF\lib</extdirs><!-- 这个配置很特殊:windows下使用分号(;)分隔,linux/mac下使用冒号(:)分隔 --><bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath></compilerArguments></configuration></plugin>

我是架构师kimze,喜欢我的文章欢迎关注我,

我会坚持分享干货: 互联网微服务架构、云原生架构、行业动态、经典案例、技术趋势,

有问题欢迎关注私信或评论区回复交流

点赞、收藏、转发、评论 对我是一种支持,感谢!

标签: #apache207