我在进行Spring in Action:第三版:第1章时遇到此错误。我设法从网站上获取源代码以进行工作。我的IDE是STS。谢谢
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - Knights:Knights:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 7 source files to E:\SpringInAction\Knights\target\classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\SpringInAction\Knights\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to E:\SpringInAction\Knights\target\test-classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
E:\SpringInAction\Knights\src\test\java\com\springinaction\knights\BraveKnightTest.java:[3,7] static import declarations are not supported in -source 1.3
(use -source 5 or higher to enable static import declarations)
import static org.mockito.Mockito.*;
E:\SpringInAction\Knights\src\test\java\com\springinaction\knights\BraveKnightTest.java:[8,3] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Test
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Aug 24 00:12:45 CDT 2011
[INFO] Final Memory: 12M/232M
[INFO] -----------------------------------------------------------
最佳答案
将此内容添加到pom以便告诉Maven使用Java版本5,默认情况下,它使用版本1.3(see documentation):
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>