How to set java system properties globally on OS X?

Short stories

I need a system level approach to Java awt. The headless property is set to true for all Java calls That is, use - DJava awt. Headless = true is not an option, because java. is being invoked from where I can not access (for example, from another tool written in Java / C / etc).

A long story

I'm using a bunch of tools that rely on AWT classes (especially Adobe's air ADT) When I run these tools on the console, they work properly But when I run them from an SSH session, they run in Java Lang. internalerror failed: unable to connect to window server - insufficient permissions Googling after I found that Java awt. Setting headless to true will solve the problem It doesn't, because ADT itself produces child Java processes without - DJava awt. headless = true.

Is there any system level way to ensure that this property is set when calling Java? Perhaps some system's AWT properties file or equivalent?

In the worst case, I can try to replace / usr / bin / Java with a shell script and add this parameter to "$@", but I want to avoid this (update: to make sure my theory is correct, try this shell script, and it solves this problem, just hope to have a cleaner solution)

Solution

It seems to support Java_ TOOL_ The options environment variable is added to the sun / Oracle JVM at least by Java 6 It is described in Java 8 documentation I haven't tested it yet, but it seems to be in openjdk too This seems to be a more standardized solution than other answers here

I can solve my problems:

JAVA_ TOOL_ OPTIONS = -Djava. awt. headless = true ant …

This successfully propagates the properties to the gradle build script (. / gradlew) called from ant By comparing ant - DJava awt. Headless = true... The property is not propagated to the child process This solution was first described in a gradle related gist on GitHub

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>