4

After compiling the java file without errors, when I try to run the class with the test units with the following command:

javac -cp .:junit-4.12.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore NameOfTheClass

I get the following error:

error: Class names, 'org.junit.runner.JUnitCore,DigPowTest, NameOfTheClass', are only accepted if annotation processing is explicitly requested

Any idea?

Thanks in advance!

2 Answers2

2

I got this error too, and thought I would post a slightly more complete answer as there have been a few visits to this question since it was posted.

There is a near duplicate of this question here: javac error: Class names are only accepted if annotation processing is explicitly requested. However, this question came up first for me on google, as my error message matched Joao's more closely (it relates to the junit framework).

Lawrence's answer above assumes that the poster was wanting to compile, but this is not the case as Joao states in his original question (and later in his comment). He had already compiled and was wanting to run the programme, but made a typo with javac in place of java. As javac expects a filename ending '.java' as standard input, it spits out the error: Class names...annotation processing... error message in response.

So if you are getting this message, when trying to run your test code, then you have probably mistyped the command.

P.S. I would have put this in a comment but do not have the reputation.

Community
  • 1
  • 1
pandamonium
  • 109
  • 7
0

Are you missing the ".java" from your filename on the complile?

i.e.

javac -cp .:junit-4.12.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore NameOfTheClass.java
Lawrence Tierney
  • 856
  • 1
  • 12
  • 30
  • No. I've seen that answer on other posts and they did not work for me. To compile I do: `javac -cp .:junit-4.12.jar NameOfTheClass.java` Which is enough to compile but to run I do the command line I mention, and I know it works because I already did it once. But even trying what you are saying, it does not work. – João Ferreira Oct 22 '15 at 15:26
  • 1
    Sorry! My mistake, to run it is: `java -cp .:junit-4.12.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore NameOfTheClass`, i.e., the same command line but instead of 'javac' is 'java' – João Ferreira Oct 22 '15 at 15:33