尝试使用maven从命令行运行Java7 Hello World Project [英] Trying to run Java7 Hello World Project from command line with maven
本文介绍了尝试使用maven从命令行运行Java7 Hello World Project的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用maven从命令行运行Java7 Hello World Project。如果我在eclipse中运行代码,我的项目运行正常,但如果我尝试执行mvn packege包,我会收到以下错误..
Trying to run Java7 Hello World Project from command line with maven.. If I run the code from within eclipse my project runs ok but if I try to do a "mvn packege" package I get the following error..
这是我的来源:
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 file:
Here is my pom.xml file:
<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
推荐答案
设置版本comiler插件的源和目标:
Set version of source and target for the comiler plugin:
http://maven.apache.org/plugins/maven-compiler-plugin/
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
这篇关于尝试使用maven从命令行运行Java7 Hello World Project的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文