gpt4 book ai didi

java - Maven JAXB 插件中出现 "Unable to create directory"错误,但仅一次

转载 作者:行者123 更新时间:2023-11-30 05:35:43 25 4
gpt4 key购买 nike

在我的 Maven 构建中,我使用 jaxb2-maven-plugin:2.2 从 XML 架构文件生成类。这些是项目中唯一的 Java 文件,即没有非生成的 Java 文件。

当我使用干净的项目运行 mvncompile 时,遇到以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc (xjc) on project awap: Unable to create directory D:\myproject\target\classes\ -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc (xjc) on project awap: Unable to create directory D:\myproject\target\classes\
at 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.MojoExecutionException: Unable to create directory D:\myproject\target\classes\
at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:482)
at org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:257)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 21 more
Caused by: java.io.IOException: Unable to create directory D:\myproject\target\classes\
at org.codehaus.plexus.util.FileUtils.forceMkdir(FileUtils.java:1615)
at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:439)
... 24 more

但是运行后,target/classes目录确实存在!事实上,如果我第二次尝试 mvncompile(中间不进行清理),构建就会成功。

最新插件版本 2.4 也会出现同样的错误。

查看source在引发异常的函数中,我看到调用了 File.mkdirs() 。我不知道为什么会返回 false。毕竟,该目录确实会在某个时候创建​​......

为什么会发生这种情况以及如何让我的构建第一次就成功?

最佳答案

所以我可以间接解决这个问题。我已将生成类的(非标准)目录标记为 maven 中的源目录。

我对此进行了更改,以便将类生成到默认的 target/generated-sources 中,并删除了额外的源文件夹。这使得错误消失。

关于java - Maven JAXB 插件中出现 "Unable to create directory"错误,但仅一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56669550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com