簡體   English   中英

在JavaFX應用程序上設置自定義圖標

[英]Setting a custom icon on javafx application

我正在嘗試在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>

是我的項目結構的屏幕截圖。

順便說一句,我正在使用IntelliJ IDEA 2017.1.4。 我也看到了以下問題:

  1. JavaFX本機包圖標OS X
  2. 在自包含的JavaFX應用程序(.exe)中包括一個圖標,我也嘗試將package / macosx放在項目文件夾中,但是沒有用。
  3. 如何在Windows上為Javafx本機包圖標設置自定義圖標

我還看到了在NetBeansIDE中完成此任務的簡單方法(例如here )。 但是由於這種簡單的問題,我不想更改IDE。 先感謝您!

編輯31.07

打開詳細模式后,我發現它期望使用Minesweeper-1.0.icns而不是Minesweeper.icns。 在沒收javafx-maven-plugin的情況下添加appName字段解決了我的問題。

您將必須添加到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文件名與<appName>內部的文件名相同,然后只需調用mvn jfx:native即可捆綁您的應用程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM