使用Bitbucket管道构建Javafx应用程序



我正在尝试使用BitBucket管道构建Javafx项目。为此,我正在使用Maven:3-JDK-8 Docker Image。此DOCKER映像使用OpenJDK 8而不是Oracle的图像(由于林肯问题(,不包括Javafx部分。请注意,我必须使用Java 8来构建我的项目!我得到的问题是,我无法单独使用Docker Image构建应用程序。

在对同一问题的答案中提出的(https://stackoverflow.com/a/40167253/2000338(:我尝试使用此bitbucket-pipelines.yml尝试克服情况:

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中,我会遇到以下错误:

[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 build而不问题。

先前方法中缺少的是javafx库不在classpath上。基本上,为了使Maven构建工作,我必须将jfxrt.jar添加到classPath中。我发现在安装Javafx后的maven:3-jdk-8图像中可以找到库中的库: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar

在构建运行期间将此文件添加到class路径将有能力。

一个想法(对我有用(是将此库纳入应用程序pom/dependecy部分作为 system范围。

在我的情况下,我为此做了一个Maven个人资料:

    <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命令才能添加此配置文件。例如。

mvn clean install -P docker_build -Djavafx-location=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar

为了简化这一点,我使用以下Dockerfile制作了Docker映像:

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文件:

<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 Hub:https://hub.docker.com/r/brzigonzales/maven-javafx

最新更新