Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven安装:";“源代码1.3”中不支持注释;_Maven_Junit_Annotations - Fatal编程技术网

Maven安装:";“源代码1.3”中不支持注释;

Maven安装:";“源代码1.3”中不支持注释;,maven,junit,annotations,Maven,Junit,Annotations,在我的项目上运行mvn install时,我发现它由于以下错误而失败: C:\Repositories\blah\src\test\java\com\xxx\qm\testrunner\test\ATest.java:[11,5] annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations) @Test C:\Repositories\blah\src\test\

在我的项目上运行
mvn install
时,我发现它由于以下错误而失败:

C:\Repositories\blah\src\test\java\com\xxx\qm\testrunner\test\ATest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Test

C:\Repositories\blah\src\test\java\com\xxx\qm\common\test\BTest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Test
但是,我的Maven依赖项包括jUnit 4.8,并且没有对1.3的任何引用


什么会导致这些错误?请告知

您需要通过使用maven编译器插件指定maven项目的源版本。将以下内容添加到pom构建元素中,并设置适当的java源代码和目标级别

<build>
     <defaultGoal>install</defaultGoal>
     <plugins>
          <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
               </configuration>
          </plugin>
      </plugins>
</build>

安装
org.apache.maven.plugins

您最有可能使用OpenJDK,其中未明确设置的源代码级别为1.3,而Oracle JDK的源代码级别为1.5

因为大多数现代Java项目的目标代码都比Java5更新,所以您很可能需要设置它

还请注意,如果您需要低于源代码的目标(例如,使用Java 6编译但部署到Java 5),可以使用Eclipse编译器而不是Java C来实现这一点。

较短的版本:

<project>
    <properties>
        <maven.compiler.source>1.5</maven.compiler.source>
        <maven.compiler.target>1.5</maven.compiler.target>
    </properties>
....

1.5
1.5
....
将此添加到pom中

<build>
       <pluginManagement>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>3.0</version>
                      <configuration>
                          <!-- put your configurations here -->
                      </configuration>
               </plugin> 
          </plugins>
       </pluginManagement>
    </build>

org.apache.maven.plugins
maven编译器插件
3

默认情况下,maven尝试使用Java 1.3版本进行编译。我希望他们中的大多数人都犯了这个错误,因为他们没有告诉maven“嘿,maven,不要使用1.3并使用“我给的任何版本”

这可以在pom.xml中提到,如下所示:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

org.apache.maven.plugins
maven编译器插件
2.5.1
真的
1.7
1.7
在上面的示例中,我使用了1.7。请替换为您想要的任何版本