gpt4 book ai didi

java - 使用带有 java 1.8 和 netbeans 的 maven-compiler-plugin 2.5.1 的 Java 注释编译错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:55:24 26 4
gpt4 key购买 nike

我刚开始用 Java 编写注释。我试图按照本教程编写自己的代码:Playing with Java annotation processing

我写的一切都是原样,但在编译过程中出现错误:

Bad service configuration file javax.annotation.processing.Processor Provider <my class> not found.

我将 netbeans 和 maven 与插件 maven-compiler-plugin v. 2.5.1 一起使用。和 Java 源 v.1.8。

在我的 pom.xml 文件中,我有(如页面中建议的)以下代码:

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- Disable annotation processing for ourselves. -->
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>

我的操作系统是 Linux(最新的 ubuntu),maven 是集成在 Netbeans 中的操作系统。

我试图用谷歌搜索它,但没有任何帮助。所有教程都是针对旧版本的插件和 Java。我尝试了旧版本的 maven-compiler-plugin 但没有效果。由于 Java 8 中引入的新功能,我无法切换到旧版本的 Java。

非常感谢您指点我如何修复它。

编辑:

这是我的来源的完整列表:

配置.java

@Retention(RetentionPolicy.SOURCE)
@Target(value = {ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER})
public @interface Config {
String name();
String type();
String defaultValue();
}

ConfigAnnotationProcessor.java

@SupportedAnnotationTypes(
{"sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotations"}
)
public class ConfigAnnotationProcessor extends AbstractProcessor {

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
Messager messager = processingEnv.getMessager();
annotations.stream().forEach((te) -> {
env.getElementsAnnotatedWith(te).stream().forEach((e) -> {
messager.printMessage(Diagnostic.Kind.NOTE,
"Printing: " + e.toString());
});
});
return true;
}

@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}

META-INF/services/javax.annotation.processing.Processor

sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotationProcessor

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sk.lieskove301.jianghongtiao</groupId>
<artifactId>MotionAnalyser</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
.... some dependencies ...
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<profiles>
<profile>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- Disable annotation processing for ourselves.-->
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

这是我的编译器日志:

cd /home/xjuraj/Dropbox/Work/MotionAnalyser; JAVA_HOME=/usr/lib/jvm/java-8-oracle /usr/local/netbeans-8.0/java/maven/bin/mvn clean install
Scanning for projects...

------------------------------------------------------------------------
Building MotionAnalyser 1.0-SNAPSHOT
------------------------------------------------------------------------

--- maven-clean-plugin:2.4.1:clean (default-clean) @ MotionAnalyser ---
Deleting /home/xjuraj/Dropbox/Work/MotionAnalyser/target

--- maven-resources-plugin:2.5:resources (default-resources) @ MotionAnalyser ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 6 resources

--- maven-compiler-plugin:2.3.2:compile (default-compile) @ MotionAnalyser ---
Compiling 27 source files to /home/xjuraj/Dropbox/Work/MotionAnalyser/target/classes
-------------------------------------------------------------
COMPILATION ERROR :
-------------------------------------------------------------
error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotationProcessor not found
1 error
-------------------------------------------------------------
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.661s
Finished at: Mon Aug 11 19:56:16 CEST 2014
Final Memory: 12M/180M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project MotionAnalyser: Compilation failure
error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotationProcessor not found
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

编辑 2 等等......:

Screenshot of my environment is here

Screenshot of my folder structure

非集成maven的输出

xjuraj@xjuraj-pc:~/Dropbox/Work/MotionAnalyser$ mvn -e package
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - sk.lieskove301.jianghongtiao:MotionAnalyser:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 27 source files to /home/xjuraj/Dropbox/Work/MotionAnalyser/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotationProcessor not found
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotationProcessor not found

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.BuildFailureException: Compilation failure
error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotationProcessor not found

at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
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:483)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider sk.lieskove301.jianghongtiao.motionanalyser.config.ConfigAnnotationProcessor not found

at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:729)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Aug 14 15:10:26 CEST 2014
[INFO] Final Memory: 19M/187M
[INFO] ------------------------------------------------------------------------

干杯,朱拉杰

最佳答案

非常感谢 bigdestroyer 的宝贵时间和帮助。我已经找到了错误所在。它在 pom.xml 文件中。我的结构是:

<project>
[...]
<dependencies>.... some dependencies ...</dependencies>
<properties>.... some properties ...</properties>
<profiles>
<profile>
<build>
<plugins>
<plugin>
... plugins & settings ...

但是标签 有问题。我删除了它们,它现在就像一个魅力。

所以我的工作 pom.xml 现在看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sk.lieskove301.jianghongtiao</groupId>
<artifactId>MotionAnalyser</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
...dependencies...
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- Disable annotation processing for ourselves.-->
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
</project>

关于java - 使用带有 java 1.8 和 netbeans 的 maven-compiler-plugin 2.5.1 的 Java 注释编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25239200/

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