JavaFX doesn't work on Heroku (NoClassDefFound

2019-07-30 07:48发布

问题:

I have some JavaFX includes in my tomcat server application, like a javafx pair, and some properties, but it seems that they cause an error on heroku:

java.lang.NoClassDefFoundError: javafx/util/Pair

I see that it installs openJDK 1.8 when deploying the war, so how come it doesn't find JavaFX?

回答1:

The JDK on Heroku is headless, and does not include the javafx JAR. You can include it manually by adding something like this to your pom.xml:

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>javafx</artifactId>
    <version>2016.10.0</version>
</dependency>

That distribution is provided by RedHat. There are other distributions on Maven Central.



回答2:

Another solution is adding this buildpack to your app:

 $ heroku buildpacks:add -i 1 https://github.com/jkutner/heroku-buildpack-javafx