[关闭]
@xtccc 2016-06-25T13:58:19.000000Z 字数 838 阅读 1988

Maven常见问题

给我写信
GitHub

此处输入图片的描述


Maven



目录


编译时的Language Level

Problem example:

A.java

  1. public interface A {
  2. void f();
  3. }



B.java

  1. public class B implements A {
  2. @Override
  3. public void f() { return; }
  4. }



用Maven编译B.java时会报错:

@Override is not allowed when implementing interface method



我们需要修改编译的语言级别 —— 用1.7来编译。

方法1:在每个pom.xml文件中增加下面一段

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins</groupId>
  5. <artifactId>maven-compiler-plugin</artifactId>
  6. <configuration>
  7. <source>1.7</source>
  8. <target>1.7</target>
  9. </configuration>
  10. </plugin>
  11. </plugins>
  12. </build>



方法2:修改~/.m2/settigns.xml文件

  1. <profile>
  2. <id>jdk-1.7</id>
  3. <activation>
  4. <jdk>1.7</jdk>
  5. <activeByDefault>true</activeByDefault>
  6. </activation>
  7. <properties>
  8. <maven.compiler.source>1.7</maven.compiler.source>
  9. <maven.compiler.target>1.7</maven.compiler.target>
  10. <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
  11. </properties>
  12. </profile>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注