pyjnius
pyjnius copied to clipboard
Can't start AWT on OS X Mavericks
While trying out the code at http://www.hackzine.org/using-apache-tika-from-python-with-jnius.html
I get the exception below. Is there any way to set StartOnFirstThread to false for the VM.
log4j:WARN No appenders could be found for logger (org.apache.pdfbox.pdfparser.PDFObjectStreamParser).
log4j:WARN Please initialize the log4j system properly.
2013-11-20 11:25:00.503 python[46783:507] Apple AWT Java VM was loaded on first thread -- can't start AWT.
Exception in thread "main" 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:1833)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1730)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.loadLibraries(Toolkit.java:1605)
at java.awt.Toolkit.<clinit>(Toolkit.java:1627)
at java.awt.Color.<clinit>(Color.java:263)
at org.apache.pdfbox.pdmodel.PDPage.<clinit>(PDPage.java:79)
at org.apache.pdfbox.pdmodel.PDPageNode.getAllKids(PDPageNode.java:212)
at org.apache.pdfbox.pdmodel.PDPageNode.getAllKids(PDPageNode.java:218)
at org.apache.pdfbox.pdmodel.PDPageNode.getAllKids(PDPageNode.java:184)
at org.apache.pdfbox.pdmodel.PDDocumentCatalog.getAllPages(PDDocumentCatalog.java:211)
at org.apache.pdfbox.util.PDFTextStripper.writeText(PDFTextStripper.java:335)
at org.apache.tika.parser.pdf.PDF2XHTML.process(PDF2XHTML.java:72)
at org.apache.tika.parser.pdf.PDFParser.parse(PDFParser.java:154)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:242)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:242)
at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:120)
at org.apache.tika.Tika.parseToString(Tika.java:380)
Traceback (most recent call last):
File "TikaTest.py", line 20, in <module>
text = tika.parseToString(FileInputStream("linkitup-camera-ready.pdf"), meta)
File "jnius_export_class.pxi", line 830, in jnius.JavaMultipleMethod.__call__ (jnius/jnius.c:21087)
File "jnius_export_class.pxi", line 562, in jnius.JavaMethod.__call__ (jnius/jnius.c:18033)
File "jnius_export_class.pxi", line 639, in jnius.JavaMethod.call_method (jnius/jnius.c:18859)
File "jnius_utils.pxi", line 39, in jnius.check_exception (jnius/jnius.c:3810)
jnius.JavaException: JVM exception occured
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
I get a similar error, possibly related – also on 10.9 – when attempting to import javax.imageio.ImageIO
via autoclass()
… here’s the traceback:
ASIO-OTUS:pylire[master •]$ python pylire/compatibility/liretests-jnius.py
2014-02-24 09:35:56.628 Python[71534:d07] Apple AWT Java VM was loaded on first thread -- can't start AWT.
Traceback (most recent call last):
File "pylire/compatibility/liretests-jnius.py", line 11, in <module>
ImageIO = jnius.autoclass('javax.imageio.ImageIO')
File "/usr/local/lib/python2.7/site-packages/jnius/reflect.py", line 150, in autoclass
c = find_javaclass(clsname)
File "jnius_export_func.pxi", line 23, in jnius.find_javaclass (jnius/jnius.c:10372)
jnius.JavaException: Class not found 'javax/imageio/ImageIO'
… I’m not any kind of Java pro but I know ImageIO
does some kind of under-the-hood AWT shenanigans because it sticks up one of those pointless and obstinate Java-app Dock icons whenever it does load successfully (like e.g. with Jython). HTH.
The solutions is to add in code file "jnius_jvm_desktop.pxi" class cdef void create_jnienv() this option options[1].optionString="-Djava.awt.headless=true". Problem solved. Don't forget to set args.nOptions=2 and cdef JavaVMOption options[2]
Same error here on Yosemite. I tried @saguas's suggestion but couldn't get that to work. So in "cdef void create_jnienv()" I simply appended the arguments with this fragment:
optarr.append("-Djava.class.path=" + jnius_config.expand_classpath())
# https://github.com/kivy/pyjnius/issues/85
optarr.append("-Djava.awt.headless=true")
That did the trick. But this is pretty convoluted and will break on the next upgrade.
Is there any way to tell jnius to use the java 1.7* jdk rather than Apple's 1.6 jdk?