繁体   English   中英

ArrayOutOfBounds在NetBeans上编译Maven插件

[英]ArrayOutOfBounds compiling maven plugin on netbeans

我正在尝试编译一个非常简单的maven插件,该插件本质ArrayOutOfBoundsException内容从一个文件夹复制到另一个文件夹,但是ArrayOutOfBoundsException总是在编译时被某个类(我猜是处理注释)抛出。 我将在编译器,插件类和POM的日志下面粘贴。
您认为这可能是该工具中的错误吗?
我该如何解决?

编译器日志

mvn -X clean deploy
...
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy', parentClassName='org.codehaus.plexus.classworlds.strategy.AbstractStrategy', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.Strategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.Strategy', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.StrategyFactory:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.StrategyFactory', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.869 s
Finished at: 2019-01-03T14:37:45-02:00
Final Memory: 15M/54M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
    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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    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-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 49272
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scanDirectory(DefaultMojoAnnotationsScanner.java:204)
    at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:95)
    at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:125)
    at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:104)
    at org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:108)
    at org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:233)
    at org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:92)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more

插件类

@Mojo(name = "backup")
public class Backup extends AbstractMojo {

    private Log log;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {

        log = getLog();

        File destination = generateFile("backup"),
                source = generateFile("src", "main", "webapp", "files");

        log.info(destination.getAbsolutePath());
        log.info(Boolean.toString(destination.exists()));
        if (destination.exists()) {
            log.info("removing pre-encountered ./backup folder");

            try {
                Files.walk(destination.toPath())
                        .sorted(Comparator.reverseOrder())
                        .map(Path::toFile)
                        .forEach(File::delete);
                if (!destination.delete()) {
                    throw new IOException("Impossible to delete folder.");
                }
            } catch (IOException ex) {
                log.error("Error deleting previous backup folder");
                throw new MojoExecutionException("Impossible to delete previous backup folder.", ex);
            }
        }

        log.debug("attempting to create ./backup dir");

        if (destination.mkdir()) {
            try {
                log.info("Beginning backup.");
                recursiveCopy(source, destination);
            } catch (IOException ex) {
                log.error("error copying files", ex);
                throw new MojoExecutionException("Error copying files", ex);
            }
        } else {
            log.error("unable to create ./backup directory");
            throw new MojoExecutionException("unable to create ./backup directory");
        }

        log.debug("backup finished");
    }

    private void recursiveCopy(File source, File destination) throws IOException {
        for (File file : source.listFiles()) {
            if (file.isDirectory()) {

                log.debug(generateString("creating folder ", file.getName()));                
                File newDest = generateFile(destination.getPath(), file.getName());

                if (newDest.mkdir()) {
                    recursiveCopy(file, newDest);
                } else {
                    String error = generateString("Unable to create folder ", file.getPath());
                    log.error(error);
                    throw new IOException(error);
                }
            } else {
                log.debug(generateString("copying ", file.getPath()));
                Files.copy(file.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }

    static String generateString(String... sts) {
        StringBuilder out = new StringBuilder();
        Arrays.stream(sts).forEach(out::append);
        return out.toString();
    }

    static File generateFile(String... paths) {
        String paths2[] = new String[paths.length * 2 - 1];

        paths2[0] = paths[0];

        for (int i = 1, j = 1; i < paths2.length; i++, j++) {
            paths2[i] = File.separator;
            paths2[++i] = paths[j];
        }

        return new File(generateString(paths2));
    }

}

如果您想知道为什么我在底部做了那些愚蠢的方法,那是因为它们避免了这个错误(使用直接字符串连接是我发现的原因之一)

和我的POM

... version, id and stuff ...
<packaging>maven-plugin</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.6.0</version>
    </dependency>
     <dependency>
         <groupId>org.apache.maven.plugin-tools</groupId>
         <artifactId>maven-plugin-annotations</artifactId>
         <version>3.6.0</version>
         <scope>provided</scope>
     </dependency>
</dependencies>

通过将运行maven-plugin-plugin :: descriptor显式添加到POM来解决

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
        <execution>
            <goals>
                <goal>descriptor</goal>
            </goals>
        </execution>
    </executions>
</plugin>

不知道为什么

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM