run javafx from python and get output

Viewed 28

i have a javafx gui programe which work fine in windows, I can run this .jar using python in my local PC and get output, but when try to do same using google colab I got this error

my JavaFX GUI file named: ex4.jar

code:

from subprocess import Popen, PIPE, STDOUT
p = Popen(['java', '-jar', 'ex4.jar' , '3'], stdout=PIPE, stderr=STDOUT)

for line in p.stdout:
  print ( line)

I got error:

b'Error: Could not find or load main class frontend.App\n'
b'Caused by: java.lang.NoClassDefFoundError: javafx/application/Application\n'
1 Answers

It looks like your java command is missing the --module-path and --add-modules option required by your JAR. Starting form this complete VersionCheck example, I added a line to print a string on STDOUT and modified your example to execute the included script.

File try.py:

#!/usr/local/bin/python3
from subprocess import Popen, PIPE, STDOUT
p = Popen(['./run.sh'], stdout=PIPE, stderr=STDOUT)

for line in p.stdout:
  print ( line)

I then ran it on the example to produce the following console output:

$ git clone https://gist.github.com/trashgod/c3e0fa… version
$ pushd version/
$ ./try.py
b'Mac OS X v12.6; Java v17.0.3.1; JavaFX v17.0.1+1\n'

version image

Related