Home > Java > body text

Maven compilation itself gives UnsupportedOperationException

王林
Release: 2024-02-09 11:39:08
forward
1205 people have browsed it

php小编鱼仔Maven是一款流行的Java项目管理工具,但在使用过程中可能会遇到一些问题。其中,一个常见的问题是在编译过程中出现UnsupportedOperationException异常。这个异常通常表示Maven在尝试编译自身时遇到了不支持的操作。本文将详细介绍这个问题的原因,并提供解决方案,以帮助开发者顺利解决这个问题。

问题内容

对于相同的 maven jdk 21 项目签出。使用相同版本的 jdk 和 maven,虽然 maven 在其他 windows 10 计算机上进行编译,但在我的 windows 10 计算机上进行相同更新的 maven 编译时出现以下异常

java.lang.UnsupportedOperationException

        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.ensureFile(ZipFileSystemProvider.java:87)
    
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:119)
    
        at jdk.compiler/com.sun.tools.javac.file.JavacFileManager$ArchiveContainer.<init>(JavacFileManager.java:566)
    
        at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.getContainer(JavacFileManager.java:329)
    
        at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.pathsAndContainers(JavacFileManager.java:1078)
    
        at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.indexPathsAndContainersByRelativeDirectory(JavacFileManager.java:1033)
    
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1228)
    
        at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.pathsAndContainers(JavacFileManager.java:1021)
    
        at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.list(JavacFileManager.java:777)
    
        at jdk.compiler/com.sun.tools.javac.main.DelegatingJavaFileManager.list(DelegatingJavaFileManager.java:83)
    
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.list(ClassFinder.java:752)
    
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.scanUserPaths(ClassFinder.java:696)
    
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:570)
    
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:311)
    
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:682)
    
        at jdk.compiler/com.sun.tools.javac.code.Symbol$PackageSymbol.members(Symbol.java:1178)
    
        at jdk.compiler/com.sun.tools.javac.code.Symtab.listPackageModules(Symtab.java:901)
    
        at jdk.compiler/com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:345)
    
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:553)
    
        at jdk.compiler/com.sun.tools.javac.comp.Enter.classEnter(Enter.java:287)
    
        at jdk.compiler/com.sun.tools.javac.comp.Enter.classEnter(Enter.java:302)
    
        at jdk.compiler/com.sun.tools.javac.comp.Enter.complete(Enter.java:608)
    
        at jdk.compiler/com.sun.tools.javac.comp.Enter.main(Enter.java:592)
    
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1072)
    
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:947)
    
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
    
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
    
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
    
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
    
        at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:136)
    
        at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:183)
    
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1140)
    
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:193)
    
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
    
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
    
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    
        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:56)
    
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
    
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
    
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
    
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
    
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Copy after login

尝试了不同版本的maven并重新安装了jdk 21和maven。并尝试使用不同版本的maven编译插件。 intellij rebuild可以使用jdk 21编译项目,但maven编译失败。从 intellij 或从命令提示符进行 maven 编译失败并出现异常。 maven在java 8上没有问题。但在jdk17和jdk21上有同样的问题。就在我的机器上。

解决方法

由于某种原因,您遇到了 maven 计算的路径不被 jdk 视为常规文件的问题。我以前没有见过这种场景,不过你可以自己看看。

我让 intellij 使用 openjdk 21 分析 maven 项目的堆栈跟踪,发现抛出异常的代码如下所示:

private boolean ensureFile(Path path) {
        try {
            BasicFileAttributes attrs =
                Files.readAttributes(path, BasicFileAttributes.class);
            if (!attrs.isRegularFile())
                throw new UnsupportedOperationException();
            return true;
        } catch (IOException ioe) {
            return false;
        }
    }
Copy after login

所以你想知道的是抛出异常时path的值是什么。由于 jdk 内的此位置没有日志记录,最简单的方法是在调试模式下运行 maven 构建(或从命令行运行 mvndebug 并附加调试器)并在此处设置断点,然后在命中断点时检查变量.

当您看到该值时,您可能会立即清楚问题所在。我的猜测是您的主目录中的 .m2/repositories 文件夹已损坏,或者它引用了文件系统中不存在的文件或目录。

The above is the detailed content of Maven compilation itself gives UnsupportedOperationException. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template