问题描述
我需要一个系统级的方式向 java.awt.headless
属性设置为真
所有Java调用的。也就是说,使用 -Djava.awt.headless = TRUE
是不是一种选择,由于Java是从地方调用我没有访问(例如从另一个工具用Java / C的/ etc。)
I need a system level way to set the java.awt.headless
property to true
for all java invocations. That is, using -Djava.awt.headless=true
is not an option, since java is being invoked from places I don't have access to (e.g. from within another tool written in Java/C/etc.)
我用了一堆用Java编写的(特别是Adobe的空气ADT)的工具,依赖于AWT类。当我在控制台上运行这些工具,他们很好地工作。但是,当我从一个SSH会话未能以 java.lang.InternalError运行它们:无法连接到窗口服务器 - 没有足够的权限
。周围的Googling我发现,设置java.awt.headless为true,将会解决这个问题。这不,那是因为ADT本身滋生孩子的Java程序的的没有的 -Djava.awt.headless = TRUE
I'm using a bunch of tools written in Java (specifically Adobe's Air ADT) that rely on AWT classes. When I run these tools on the console they work fine. But when I run them from an SSH session they fail with java.lang.InternalError: Can't connect to window server - not enough permissions
. Googling around I found that setting java.awt.headless to true will fix the problem. It doesn't, and that's because ADT itself spawns children Java processes without -Djava.awt.headless=true
.
有没有系统级的方法,以确保此属性设置时的Java调用?也许有些系统AWT属性文件或等效?
Is there any system-level way to ensure this property is set whenever Java is invoked? Maybe some system awt property file or equivalent?
最坏的情况,我可以尝试更换的/ usr / bin中/ java的
用shell脚本,会将此参数$ @
,但我希望能避免这种情况。 (更新:只是为了确保我的理论是正确的,试过这个shell脚本黑客,它不会解决问题只是希望有一个更清洁的解决方案。)
Worst case scenario I could try replacing /usr/bin/java
with a shell script that adds this argument to "$@"
but I'm hoping to avoid that. (Update: Just to ensure my theory is right, tried this shell script hack and it does solve the problem. Just hoping for a cleaner solution)
推荐答案
使用 _JAVA_OPTIONS
,而不是 JAVA_OPTS
的。 _JAVA_OPTIONS
将得到回升时,会自动运行java。
Use _JAVA_OPTIONS
instead of JAVA_OPTS
. _JAVA_OPTIONS
will get picked up automatically when you run java.
export _JAVA_OPTIONS=-Djava.awt.headless=true
adt ...
我知道这是真的在OS X这表明,这可能工作在Windows和Linux,以及。
I know this is true on OS X.This indicates that this may work on Windows and Linux, as well.
这篇关于如何在全球范围内对OS X的Java系统属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!