[Solved] Class names are only accepted if annotation processing is explicitly requested

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:

When we will compile the above class with javac as below:

C:\Users\Arpit\Desktop\javaPrograms>javac HelloWorldExample
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

We can simply resolve this issue by appending .java at the end of file name and it should resolve the issue.

C:\Users\Arpit\Desktop\javaPrograms>javac HelloWorldExample.java

C:\Users\Arpit\Desktop\javaPrograms>

As you can see, we did not get any error now.

It may also happen if you are doing improper capitalization of .java extension while compiling.

C:\Users\Arpit\Desktop\javaPrograms>javac HelloWorldExample.Java
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.
That’s all about how to fix error:class names are only accepted if annotation processing is explicitly requested.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.