Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple AWT Issue #21

Closed
jbilcke opened this issue Oct 13, 2012 · 4 comments
Closed

Apple AWT Issue #21

jbilcke opened this issue Oct 13, 2012 · 4 comments

Comments

@jbilcke
Copy link

jbilcke commented Oct 13, 2012

Hi,

I have some issues when running a library (Sikuli) on Mac:

2012-10-13 22:17:40.469 node[34314:707] Apple AWT Java VM was loaded on first thread -- can't start AWT.

node_modules/java/lib/nodeJavaBridge.js:16
  var clazz = java.findClassSync(name); // TODO: change to Class.forName when 
                   ^
Error: Could not create class org.sikuli.script.Screen
java.lang.InternalError: Can't start the AWT because Java was started on the first thread.  Make sure StartOnFirstThread is not specified in your application's Info.plist or on the command line
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1724)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1045)
    at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
    at java.security.AccessController.doPrivileged(Native Method)
    at apple.awt.CGraphicsEnvironment.<clinit>(CGraphicsEnvironment.java:23)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
    at org.sikuli.script.Screen.<clinit>(Screen.java:25)

    at Java.java.import (node_modules/java/lib/nodeJavaBridge.js:16:20)
    at Object.<anonymous> (sikuli.js:15:35)
    at Object.<anonymous> (sikuli.js:18:4)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)

I tried to do:

  var java = require("java");
  java.options.push("-XstartOnFirstThread");

but it didn't work:

Unrecognized option: -XstartOnFirstThread
Segmentation fault: 11

I also tried -Djava.awt.headless=true, without much success:

node_modules/java/lib/nodeJavaBridge.js:16
  var clazz = java.findClassSync(name); // TODO: change to Class.forName when 
                   ^
Error: Could not create class org.sikuli.script.Screen
java.lang.ExceptionInInitializerError
Caused by: java.awt.HeadlessException
    at sun.java2d.HeadlessGraphicsEnvironment.getScreenDevices(HeadlessGraphicsEnvironment.java:59)
    at org.sikuli.script.Screen.<clinit>(Screen.java:26)

    at Java.java.import (node_modules/java/lib/nodeJavaBridge.js:16:20)
    at Object.<anonymous> (sikuli.js:17:35)
    at Object.<anonymous> (sikuli.js:20:4)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)

Any ideas?

thanks!

@jbilcke
Copy link
Author

jbilcke commented Oct 13, 2012

Well actually, I think I'm dumb.. the error message clearly says I shouldn't add the startOnFirstThread :)

" Make sure StartOnFirstThread is not specified in your application's Info.plist or on the command line
at java.lang.ClassLoader$NativeLibrary.load(Native Method)"

However, I only know how to add parameters, not how to remove them, hm.. so I'm still stuck

@ghost
Copy link

ghost commented Apr 5, 2017

The problem is with CGraphicsEnvironment

Running this:
java.import("sun.awt.CGraphicsEnvironment");
causes the script to hang

No idea how to further debug

@relsqui
Copy link

relsqui commented Mar 14, 2018

@mgc found a solution to this one:

process.env['JAVA_STARTED_ON_FIRST_THREAD_' + process.pid] = '1'

added before any instantiations worked like a charm for me.

ctrueden added a commit to imagej/imagej-node that referenced this issue May 17, 2018
When running in a vanilla node environment on macOS, Java cannot be
loaded from the application's main thread. And I guess javascript
typically runs single threaded, so we cannot simply defer the loading.

One workaround is to use headless mode. See joeferner/node-java#21.
Another is to use Electron, where it appears the threading is different.
@jbilcke
Copy link
Author

jbilcke commented May 23, 2018

I think it is time I close this 6 years old issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants