Nin*_*nja 155 java linux macos maven
我是maven的新手,也是MacOS的新手.
我在我的终端设置了maven,当获得版本设置(使用mvn -v)时,似乎它使用了JDK 1.6,而我安装了JDK 1.7.有什么不对的吗?
我输入的命令是:
blues:helloworld Ninja$ java -version
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)java version "1.7.0_05" Java(TM) SE Runtime Environment (build 1.7.0_05-b06) Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)`
blues:helloworld Ninja$ mvn -v
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-28 10:15:32+0800) Maven home: /usr/local/Cellar/maven/3.1.0/libexec Java version: 1.6.0_51, vendor: Apple Inc. Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home Default locale: zh_CN, platform encoding: EUC_CN OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"
Gau*_*ish 226
将以下内容添加到您的~/.mavenrc:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/{jdk-version}/Contents/Home
Run Code Online (Sandbox Code Playgroud)
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
小智 45
进入
/System/Library/Frameworks/JavaVM.framework/Versions
Run Code Online (Sandbox Code Playgroud)
并更新CurrentJDK指向的符号链接
/Library/Java/JavaVirtualMachines/YOUR_JDK_VERSION/Contents/
Run Code Online (Sandbox Code Playgroud)
例如
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/ CurrentJDK
Run Code Online (Sandbox Code Playgroud)
现在它将立即起作用.
小智 41
你也可以这样做,
<properties>
...
<!-- maven-compiler-plugin , aka JAVA Compiler 1.7 -->
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
...
</properties>
Run Code Online (Sandbox Code Playgroud)
red*_*IVE 27
您还可以明确告诉maven要编译哪个java版本.您可以尝试添加maven-compiler-plugin到您的pom.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Run Code Online (Sandbox Code Playgroud)
如果您将maven项目导入IDE,则IDE中可能存在maven设置,用于maven runner正在使用的默认编译器.
它帮助了我.只需将其添加到您的pom.xml中即可.
默认情况下,maven编译器插件使用Java 1.5或1.6,您必须在pom.xml中重新定义它.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
134103 次 |
| 最近记录: |