In pom.xml
you can:
在pom.xml中,您可以:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
How does Maven know where I have 1.5 version?
Maven如何知道我有1.5版本?
3 个解决方案
#1
As far as I know, this will not make Maven compile against the Java 1.5 libraries. This will only tell the compiler to accept 1.5-level source code and produce 1.5-level class files.
据我所知,这不会使Maven针对Java 1.5库进行编译。这只会告诉编译器接受1.5级源代码并生成1.5级的类文件。
Your code could still possibly refer to Java 6 classes, as long as your Maven task is run with a Java 6 JVM.
只要您的Maven任务使用Java 6 JVM运行,您的代码仍可能引用Java 6类。
IF you execute:
如果您执行:
mvn -v
The output will show you what version of Java is being used. For example:
输出将显示正在使用的Java版本。例如:
Apache Maven 2.1.0 (r755702; 2009-03-18 19:10:27+0000)
Java version: 1.6.0_13
Java home: C:\Program Files\Java\jdk1.6.0_13\jre
Default locale: en_IE, platform encoding: Cp1252
OS name: "windows vista" version: "6.0" arch: "x86" Family: "windows"
#2
I take it that we are talking about Maven here. I would guess via the JAVA_HOME environmental variable. If Windows do a echo %JAVA_HOME% or Linux do a echo $JAVA_HOME and see.
我认为我们在这里谈论Maven。我猜想通过JAVA_HOME环境变量。如果Windows执行echo%JAVA_HOME%或Linux执行echo $ JAVA_HOME并查看。
Oops: Sorry I see it is Maven.
哎呀:对不起,我看到它是Maven。
#3
I knew that maven had figured out where to find my JDK without me setting $JAVA_HOME. After removing the default JDK version, Maven was still looking in the original location and throwing an error.
我知道maven在没有设置$ JAVA_HOME的情况下找到了在哪里找到我的JDK。删除默认的JDK版本后,Maven仍在寻找原始位置并抛出错误。
I didn't want to set $JAVA_HOME if there was a mechanism already in place. Eventually I found ~/.mavenrc, which contained the setting of JAVA_HOME.
如果已有机制,我不想设置$ JAVA_HOME。最终我找到〜/ .mavenrc,其中包含JAVA_HOME的设置。
I fixed this, and presto, things were happy.
我解决了这个问题,而且事情很快乐。
#1
As far as I know, this will not make Maven compile against the Java 1.5 libraries. This will only tell the compiler to accept 1.5-level source code and produce 1.5-level class files.
据我所知,这不会使Maven针对Java 1.5库进行编译。这只会告诉编译器接受1.5级源代码并生成1.5级的类文件。
Your code could still possibly refer to Java 6 classes, as long as your Maven task is run with a Java 6 JVM.
只要您的Maven任务使用Java 6 JVM运行,您的代码仍可能引用Java 6类。
IF you execute:
如果您执行:
mvn -v
The output will show you what version of Java is being used. For example:
输出将显示正在使用的Java版本。例如:
Apache Maven 2.1.0 (r755702; 2009-03-18 19:10:27+0000)
Java version: 1.6.0_13
Java home: C:\Program Files\Java\jdk1.6.0_13\jre
Default locale: en_IE, platform encoding: Cp1252
OS name: "windows vista" version: "6.0" arch: "x86" Family: "windows"
#2
I take it that we are talking about Maven here. I would guess via the JAVA_HOME environmental variable. If Windows do a echo %JAVA_HOME% or Linux do a echo $JAVA_HOME and see.
我认为我们在这里谈论Maven。我猜想通过JAVA_HOME环境变量。如果Windows执行echo%JAVA_HOME%或Linux执行echo $ JAVA_HOME并查看。
Oops: Sorry I see it is Maven.
哎呀:对不起,我看到它是Maven。
#3
I knew that maven had figured out where to find my JDK without me setting $JAVA_HOME. After removing the default JDK version, Maven was still looking in the original location and throwing an error.
我知道maven在没有设置$ JAVA_HOME的情况下找到了在哪里找到我的JDK。删除默认的JDK版本后,Maven仍在寻找原始位置并抛出错误。
I didn't want to set $JAVA_HOME if there was a mechanism already in place. Eventually I found ~/.mavenrc, which contained the setting of JAVA_HOME.
如果已有机制,我不想设置$ JAVA_HOME。最终我找到〜/ .mavenrc,其中包含JAVA_HOME的设置。
I fixed this, and presto, things were happy.
我解决了这个问题,而且事情很快乐。