3

操作系统 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
4

2 回答 2

2

我建议

export JAVA_HOME=$(/usr/libexec/java_home)

在您的.profile,.bashrc或其他登录时获取的文件中。

http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/

于 2014-02-14T19:17:33.717 回答
2

我遇到了同样的问题,Grails 正在使用 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK 中的 java。您可以通过将 Grails 指向 $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 - 这可能不是最好的答案

于 2013-04-24T13:11:38.170 回答