Table of Contents
In this post, we will see how to resolve class names are only accepted if annotation processing is explicitly requested
in java.
Problem: class names are only accepted if annotation processing is explicitly requested
You will get this error when you are trying to compile java program without .java
extension.
Let’s reproduce this issue with the help of an example:
1 2 3 4 5 6 7 8 9 |
package org.arpit.java2blog; public class HelloWorldExample { public static void main(String[] args) { System.out.println("Hello world"); } } |
When we will compile the above class with javac as below:
error: Class names, ‘HelloWorldExample’, are only accepted if annotation processing is explicitly requested
1 error
As you can see got error:class names are only accepted if annotation processing is explicitly requested
because we did not add .java
suffix in HelloWorldExample
.
Solution: class names are only accepted if annotation processing is explicitly requested
Solution 1
We can simply resolve this issue by appending .java
at the end of file name and it should resolve the issue.
C:\javaPrograms>
As you can see, we did not get any error now.
Solution 2
It may also happen if you are doing improper capitalization of .java
extension while compiling.
error: Class names, ‘HelloWorldExample.Java’, are only accepted if annotation processing is explicitly requested
1 error
If you notice, filename should be HelloWorldExample.java rather than HelloWorldExample.Java.
Solution 3
If you are compiling and running at the same time, use &&
to concat two commands.
Solution 4
Are you running javac
to run the program as well.
C:\javaPrograms>javac HelloWorldExample
Use java
instead of javac
to run the program.
Correct way to do it:
C:\javaPrograms>java HelloWorldExample
Solution 5
Are you running this command from folder named "Java", if yes, change the folder name.
That’s all about how to fix error:class names are only accepted if annotation processing is explicitly requested
.