尝试使用maven从命令行运行Java7 Hello World项目。如果我在eclipse中运行代码,我的项目可以正常运行,但是如果我尝试执行“mvn packege”包,我会得到以下错误:
这是我的源代码:
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!, Tesing Java 7" );
printDay("Wednesday");
}
public static void printDay(String dayOfWeek) {
switch (dayOfWeek)
{
case "Sunday": System.out.println("Dimanche"); break;
case "Monday": System.out.println("Lundi"); break;
case "Tuesday": System.out.println("Mardi"); break;
case "Wednesday": System.out.println("Mercredi"); break;
case "Thursday": System.out.println("Jeudi"); break;
case "Friday": System.out.println("Vendredi"); break;
case "Saturday": System.out.println("Samedi"); break;
default: System.out.println("Error: '"+ dayOfWeek +"' is not a day of the week"); break;
}
}
}
这是我的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>org.smith</groupId>
<artifactId>TestJava7</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestJava7</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>
这里是错误信息:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/jsmith/Documents/workspace-juno/TestJava7/src/main/java/org/smith/TestJava7/App.java:[16,13] error: strings in switch are not supported in -source 1.5
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.169s
[INFO] Finished at: Wed Jan 16 09:48:26 EST 2013
[INFO] Final Memory: 10M/100M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project TestJava7: Compilation failure
[ERROR] /home/jsmith/Documents/workspace-juno/TestJava7/src/main/java/org/smith/TestJava7/App.java:[16,13] error: strings in switch are not supported in -source 1.5
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException