[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:\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

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>javac HelloWorldExample.java

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.

C:\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.

C:\javaPrograms>javac HelloWorldExample.java

Solution 3

If you are compiling and running at the same time, use && to concat two commands.

C:\javaPrograms>javac HelloWorldExample.java && java HelloWorldExample

Solution 4

Are you running javac to run the program as well.

C:\javaPrograms>javac HelloWorldExample.Java
C:\javaPrograms>javac HelloWorldExample

Use java instead of javac to run the program.

Correct way to do it:

C:\javaPrograms>javac HelloWorldExample.Java
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.

Was this post helpful?

Leave a Reply

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