gpt4 book ai didi

java - 为什么 Grails 在 Mac OS x 7 上使用旧的 JVM 编译器?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:01 25 4
gpt4 key购买 nike

Mac 操作系统 x 10.7

grails> !java -version
java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

grails> !which java
/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home/bin/java

我想在其中一项服务中使用 Java 1.7 NIO,我得到了以下信息:

grails> run-app 
...
| Error Compilation error: startup failed:
/path/to/Acquiring.groovy: 7: unable to resolve class java.nio.file.FileSystems
@ line 7, column 1.
import java.nio.file.FileSystems
^
/path/to/Acquiring.groovy: 8: unable to resolve class java.nio.file.Path
@ line 8, column 1.
import java.nio.file.Path
^
2 errors
| Error Error running script run-app : org.codehaus.groovy.grails.cli.ScriptExitException (Use --stacktrace to see the full trace)

什么鬼!?好的。我在代码中检查 java 版本:println

println System.getProperty("java.version").startsWith('1.6')?
"I use 1.6?! WTF?!":"It's ok"

终于看到了

I use 1.6?! WTF?!

或者更具体地说

    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
println System.getProperty("java.version").startsWith('1.6')?"I use 1.6?! WTF?!":"It's ok";
println "VM_vmVendor: " + RuntimemxBean.vmVendor
println "VM_getName: " + RuntimemxBean.getName()
println "VM_getVmVersion: " + RuntimemxBean.getVmVersion()
println "VM_getVmName: " + RuntimemxBean.getVmName()
println "VM_namevendor: " + RuntimemxBean.getLibraryPath()

println "VM_getSystemProperties:" +
"\n ================= \n" + RuntimemxBean.getSystemProperties() +
"\n ================= "

List<String> arguments = RuntimemxBean.getInputArguments();
arguments.each { print it+ "\n" }

变成:

I use 1.6?! WTF?!
VM_vmVendor: Apple Inc.
VM_getName: 91621@air.local
VM_getVmVersion: 20.14-b01-445
VM_getVmName: Java HotSpot(TM) 64-Bit Server VM
VM_namevendor: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
VM_getSystemProperties:
=================
[java.vm.version:20.14-b01-445, java.vendor.url:http://www.apple.com/, sun.jnu.encoding:MacRoman, grails.interactive.mode.enabled:true, java.vm.info:mixed mode, user.dir:/Users/me/Sites/java/grailsnew, grails.buildScope:all, sun.cpu.isalist:, java.awt.graphicsenv:apple.awt.CGraphicsEnvironment, sun.os.patch.level:unknown, catalina.useNaming:true, tools.jar:/Library/Java/Home/lib/tools.jar, java.io.tmpdir:/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/, user.home:/Users/me, java.awt.printerjob:apple.awt.CPrinterJob, java.version:1.6.0_41, file.encoding.pkg:sun.io, java.vendor.url.bug:http://bugreport.apple.com/, mrj.build:11M4107, file.encoding:UTF-8, line.separator:
, sun.java.command:org.codehaus.groovy.grails.cli.support.GrailsStarter --main org.codehaus.groovy.grails.cli.GrailsScriptRunner --conf /Users/me/.grails/wrapper/2.2.0/grails-2.2.0/conf/groovy-starter.conf --classpath , javax.sql.DataSource.Factory:org.apache.commons.dbcp.BasicDataSourceFactory, java.vm.specification.vendor:Sun Microsystems Inc., grails.version:2.2.0, catalina.home:/Users/me/.grails/2.2.0/projects/grailsnew/tomcat, java.vm.vendor:Apple Inc., base.name:grailsnew, java.class.path:/Users/me/.grails/wrapper/2.2.0/grails-2.2.0/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-2.0.5.jar:/Users/me/.grails/wrapper/2.2.0/grails-2.2.0/dist/grails-bootstrap-2.2.0.jar:/System/Library/Java/Support:/Users/me/.grails/wrapper/2.2.0/grails-2.2.0/lib/org.springsource.springloaded/springloaded-core/jars/springloaded-core-1.1.1.jar, awt.nativeDoubleBuffering:true, sun.io.unicode.encoding:UnicodeLittle, os.arch:x86_64, user.language:en, user.name:root, java.runtime.version:1.6.0_41-b02-445-11M4107, sun.boot.class.path:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar, gopherProxySet:false, sun.cpu.endian:little, groovy.starter.conf:/Users/me/.grails/wrapper/2.2.0/grails-2.2.0/conf/groovy-starter.conf, grails.env:development, ftp.nonProxyHosts:local|*.local|169.254/16|*.169.254/16, awt.toolkit:apple.awt.CToolkit, base.dir:/Users/me/Sites/java/grailsnew, sun.boot.library.path:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries, java.vm.name:Java HotSpot(TM) 64-Bit Server VM, java.home:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home, net.sf.ehcache.skipUpdateCheck:true, grails.disable.exit:true, java.endorsed.dirs:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/endorsed, sun.management.compiler:HotSpot 64-Bit Tiered Compilers, jna.platform.library.path:/usr/lib:/usr/lib, java.naming.factory.initial:org.apache.naming.java.javaURLContextFactory, java.runtime.name:Java(TM) SE Runtime Environment, catalina.base:/Users/me/.grails/2.2.0/projects/grailsnew/tomcat, grails.home:/Users/me/.grails/wrapper/2.2.0/grails-2.2.0, java.library.path:.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java, file.separator:/, java.specification.vendor:Sun Microsystems Inc., java.vm.specification.version:1.0, sun.java.launcher:SUN_STANDARD, grails.env.default:true, grails.env.set:true, user.timezone:Europe/Moscow, program.name:grails, http.nonProxyHosts:local|*.local|169.254/16|*.169.254/16, os.name:Mac OS X, path.separator::, java.ext.dirs:/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext, sun.arch.data.model:64, java.specification.name:Java Platform API Specification, os.version:10.7.5, mrj.version:1070.1.6.0_41-445, grails.env.initializing:false, springloaded:profile=grails;cacheDir=/Users/me/.grails/2.2.0/, grails.cli.args:, java.class.version:50.0, user.country:US, java.vendor:Apple Inc., socksNonProxyHosts:local|*.local|169.254/16|*.169.254/16, java.vm.specification.name:Java Virtual Machine Specification, org.mortbay.xml.XmlParser.NotValidating:true, java.specification.version:1.6, grails.server.factory:org.grails.plugins.tomcat.TomcatServerFactory, grails.shutdown.hook.installed:true, java.naming.factory.url.pkgs:org.apache.naming]
=================
-Xserver
-Xmx768M
-Xms64M
-XX:PermSize=32m
-XX:MaxPermSize=256m
-Dfile.encoding=UTF-8
-javaagent:/Users/me/.grails/wrapper/2.2.0/grails-2.2.0/lib/org.springsource.springloaded/springloaded-core/jars/springloaded-core-1.1.1.jar
-Xverify:none
-Dspringloaded=profile=grails;cacheDir=/Users/me/.grails/2.2.0/
-Dgrails.home=/Users/me/.grails/wrapper/2.2.0/grails-2.2.0
-Dtools.jar=/Library/Java/Home/lib/tools.jar

最佳答案

我有同样的问题,Grails 正在使用/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK 中的 java。您可以通过在 $JAVA_HOME 中指向它来强制 Grails 使用不同的版本 - 将以下内容添加到您的 ~/.profile 或全局/etc/profile

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home; export JAVA_HOME

获取您的配置文件,Grails 应该在 1.7.0_13 版本上运行

注意:我不是 Java 开发人员,我需要快速启动和运行 grails - 这可能不是最佳答案

关于java - 为什么 Grails 在 Mac OS x 7 上使用旧的 JVM 编译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15201703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com