String.format
我遇到了一个问题,每当我尝试在我的代码中使用时,Maven 编译过程似乎都会引发错误。
我将 Maven 3.0.4 与 Java 1.7.0_25 一起使用。我创建了一个这样的测试项目:
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -groupId=com.mycompany.app -DartifactId=testapp
然后我将位于的主要方法更改src/main/java/com/mycompany/app/App.java
为:
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( String.format("Hello World!") );
}
}
注意通话String.format
中的。System.out.println
执行时mvn compile
,我现在收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project testapp: Compilation failure
[ERROR] /home/me/projects/java/testapp/src/main/java/com/mycompany/app/App.java:[11,34] error: cannot find symbol
[ERROR] -> [Help 1]
我不知道如何解决这个问题。为了完整起见,这是我生成的pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>testapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
更新
Maven 版本信息:
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_AU, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-37-generic", arch: "amd64", family: "unix"