【问题标题】:Setting a custom icon on javafx application在 javafx 应用程序上设置自定义图标
【发布时间】:2018-01-03 10:34:53
【问题描述】:

我正在尝试在 macos 上构建原生包并添加自定义图标而不是默认 java。

我将我的 128x128 icns 文件放在 src/main/deploy/package/macosx 中,在 pom.xml 中添加 javafx-maven-plugin 并运行命令 mvn jfx:build-native(或 mvn jfx:native)。什么也没有发生。意味着它已成功构建,但仍使用默认图标。我做错了什么?

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>StarWars</groupId>
    <artifactId>Minesweeper</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mainClass>example.minesweeper.Main</mainClass>
        <application.title>${project.artifactId}</application.title>
        <copyright>Han Solo</copyright>
    </properties>

    <organization>
        <name>Star Wars</name>
    </organization>

    <name>Minesweeper</name>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-core</artifactId>
            <version>4.0.6-alpha</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit</artifactId>
            <version>4.0.6-alpha</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.zenjava</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>8.8.3</version>
                <configuration>
                    <vendor>AndreySerebryanskiy</vendor>
                    <mainClass>example.minesweeper.Main</mainClass>
                    <deployDir>${project.basedir}/src/main/deploy</deployDir>
                </configuration>
            </plugin>
        </plugins>


    </build>


</project>

here 是我的项目结构的截图。

顺便说一句,我使用的是 IntelliJ IDEA 2017.1.4。我也看过这一系列的问题:

  1. JavaFX native bundle icon OS X
  2. including an icon into a self-contained JavaFX application (.exe) 我也尝试将 package/macosx 放在项目文件夹中,但没有成功。
  3. How to set custom icon for javafx native package icon on Windows

我还看到了在 NetBeansIDE 中完成此任务的一种简单方法(例如 here)。但我不想因为这么简单的问题而改变 IDE。 提前谢谢!

编辑 31.07

打开详细模式后,我发现它期待的是 Minesweeper-1.0.icns 而不是 Minesweeper.icns。在 javafx-maven-plugin 的配置中添加 appName 字段解决了我的问题。

【问题讨论】:

  • 在 javafx-maven-plugin 配置块中有 &lt;verbose&gt;true&lt;/verbose&gt; 时,您的系统会写什么?请将此添加到您的问题中! (免责声明:我是 javafx-maven-plugin 的维护者)
  • 由于您尚未将 javafx-maven-plugin 配置为使用 maven-lifecycle 运行,因此您必须执行 mvn jfx:native 而不是 mvn jfx:build-native,最后一个仅在执行块内
  • 肯定可以找到问题,如果我打开详细模式,谢谢!似乎它正在等待 Minesweeper-1.0.icns 作为图标,而我正在提供 Minesweeper.icns。

标签: maven intellij-idea javafx-8


【解决方案1】:

您必须添加到您的 javafx-maven-plugin 配置中。

        <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>8.8.3</version>
            <configuration>
                <vendor>AndreySerebryanskiy</vendor>
                <mainClass>example.minesweeper.Main</mainClass>
                <deployDir>${project.basedir}/src/main/deploy</deployDir>
                <verbose>true</verbose><!-- always a good idea to have this set to true while debugging -->
                <appName>Minesweeper</appName>
            </configuration>
        </plugin>

请确保您的 ICNS 文件名与 &lt;appName&gt; 中的相同,然后只需调用 mvn jfx:native 以捆绑您的应用程序。

【讨论】:

  • 非常感谢!添加 appName 字段有助于解决我的问题。
猜你喜欢
  • 1970-01-01
  • 2013-03-30
  • 2018-05-24
  • 1970-01-01
  • 1970-01-01
  • 2021-05-20
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
相关资源
最近更新 更多