1

I'am trying to test a class with Jnuit 4 in a maven project. The test runs successfully when I run it from my STS, but when I try to run it from maven command line, I get the following error: annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations) @Before

Code under test is:

public class MyContollerTest{ @Before public void setup(){ System.out.println("This is MyControllerTest before..."); } @Test public void testShouldTest(){ System.out.println("This is MyControllerTest"); } @After public void tearDown(){ System.out.println("This is MyControllerTest after..."); } } 

I'm using the Junit 4.8.1 as maven dependecy

I have checked my complience level is 1.6 and I'm using jdk 1.6

2 Answers 2

3

You'll need to add maven-compiler-plugin config in the build section of the pom.xml

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <verbose>true</verbose> <compilerVersion>1.6</compilerVersion> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> 
Sign up to request clarification or add additional context in comments.

Comments

1

Did you set appropriate source and target of your maven-compiler-plugin according to the documentation?

2 Comments

@Boris/@Constantiner you are a star!!! I added maven-compiler-plugin and it worked like a charm :-) Thanks.
So you can accept one of the answers and/or vote up for both or an other :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.