简体   繁体   English

如何在Java 1.8中使用com.apple?

[英]How to use com.apple in Java 1.8?

When compiling a Java Mac application using Gradle I get errors like this: 使用Gradle编译Java Mac应用程序时,出现如下错误:

error: package com.apple.eawt does not exist

But com.apple.eawt is present in /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar 但是com.apple.eawt位于/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar

If I copy rt.jar to some other location and add it to the class path eg by 如果我将rt.jar复制到其他位置并将其添加到类路径中,例如通过

compile fileTree(dir: '/Users/XXX', include: 'rt.jar')

then it magically works! 然后神奇地工作! Is there some trick to persuade Java to use platform dependent stuff in rt.jar ? 有说服Java在rt.jar使用平台相关内容的技巧吗?

I found the solution: 我找到了解决方案:

compileJava {
    options.compilerArgs << "-XDignore.symbol.file=true"
    options.fork = true
    options.forkOptions.executable = 'javac'
}

I know this is a bit old but I thought it might be useful to someone. 我知道这有点老了,但我认为这可能对某人有用。 With gradle 3.5 the forkOptions.executable is deprecated. 在gradle 3.5中,不推荐使用forkOptions.executable。 The javaHome property must be used instead: 必须改为使用javaHome属性:

compileJava {
  options.fork = true
  options.forkOptions.javaHome = new File("${System.properties.'java.home'}")
  options.compilerArgs << "-XDignore.symbol.file=true"
}

See the JavaDoc of the ForkOptions class https://docs.gradle.org/3.5.1/javadoc/org/gradle/api/tasks/compile/ForkOptions.html 请参阅ForkOptions类的JavaDoc https://docs.gradle.org/3.5.1/javadoc/org/gradle/api/tasks/compile/ForkOptions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM