使用Bitbucket管道构建JavaFx应用程序 [英] Building JavaFx application using Bitbucket pipelines
问题描述
我正在尝试使用bitbucket管道构建JavaFx项目.为此,我正在使用maven:3-jdk-8 docker image.此Docker映像使用OpenJDK 8而不是Oracle的OpenJDK 8(由于许可证问题),其中不包括JavaFx部分.请注意,我必须使用Java 8来构建我的项目! 我遇到的问题是我无法仅使用该docker映像来构建应用程序.
I am trying to build JavaFx project using bitbucket pipelines. For that I am using maven:3-jdk-8 docker image. This Docker image uses OpenJDK 8 instead of Oracle's one (due to the lincensing issue) which does not include the JavaFx part. Note that I have to use Java 8 to build my project! Problem that I am getting is that I am not able to build the application using that docker image alone.
根据对同一问题的回答中提出的建议( https://stackoverflow.com/a/40167253/2000338 ): 我尝试使用此bitbucket-pipelines.yml尝试克服这种情况:
As proposed in an answer to the same question (https://stackoverflow.com/a/40167253/2000338): I tried using this bitbucket-pipelines.yml to try to overcome the situation:
image: maven:3-jdk-8
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- apt-get update
- apt-get install -y openjfx
- mvn clean install # -B batch mode makes Maven less verbose
在步骤2中,似乎已正确安装了openjfx. 但是在步骤3中,我收到以下错误消息:
In step 2 it seems that openjfx is installed properly. But in step 3 I am getting following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project ***********: Compilation failure: Compilation failure:
[ERROR] /opt/atlassian/pipelines/agent/build/src/main/java/********/******/****/MainFx.java:[7,26] package javafx.application does not exist
它似乎仍然在抱怨缺少JavaFx库,但是我不知道为什么. 在开发人员机器上(Windows 7,jdk1.8.0_221),我可以执行maven构建,而不会出现问题.
It seams that it is still complaining on the JavaFx libraries missing, but I am not aware of why. On my developer machine (Windows 7, jdk1.8.0_221) I can execute maven build without an issue.
推荐答案
以前的方法缺少的是javafx库不在类路径中.基本上为了使Maven构建工作,我必须将jfxrt.jar添加到类路径中.
我发现在安装javafx之后的maven:3-jdk-8
映像中,可以在以下位置找到该库:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar
What was missing in previous approach is that the javafx library was not on the classpath. Basically in order to make maven build work I had to add the jfxrt.jar to the classpath.
I found that in the maven:3-jdk-8
image after installing javafx the library can be found in:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar
在构建过程中将此文件添加到类路径中即可解决问题.
Adding this file to a classpath during build run will do the trick.
(对我有用)的一个想法是将该库作为system
范围包含在应用程序pom/dependecy部分中.
One idea (that worked for me) is to include this library in application pom/dependecy part as a system
scope.
就我而言,我为此做了一个Maven个人资料:
In my case I made a maven profile for that:
<profiles>
<profile>
<id>docker_build</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javaFX</artifactId>
<version>2.2</version>
<scope>system</scope>
<systemPath>${javafx-location}</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
要运行此Maven构建,必须发出适当的maven命令以添加此配置文件.例如.
In order to run this maven build you have to issue proper maven command to add this profile. E.g.
mvn clean install -P docker_build -Djavafx-location=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar
为简化此操作,我使用以下Dockerfile制作了Docker映像:
To simplify this I made a Docker image using following Dockerfile:
FROM maven:3-jdk-8
RUN apt-get update && \
apt-get install -y --no-install-recommends openjfx
COPY settings.xml /root/.m2/
使用以下maven settings.xml文件:
which uses following maven settings.xml file:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/usr/share/maven/ref/repository</localRepository>
<activeProfiles>
<activeProfile>docker_build</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>docker_build</id>
<properties>
<javafx-location>/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar</javafx-location>
</properties>
</profile>
</profiles>
</settings>
如果有人发现它有用,我也将其发布到了Docker中心: https://hub.docker.com/r/brzigonzales/maven-javafx
I also published it to the Docker hub if somebody may find it useful: https://hub.docker.com/r/brzigonzales/maven-javafx
这篇关于使用Bitbucket管道构建JavaFx应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!