Include icon in Self-Contained JavaFX application

前端 未结 4 677
深忆病人
深忆病人 2020-12-15 12:51

I\'ve been fighting with this for over a day and have read many posts on SO and other places, but I\'m still having problems.

I need to include my application icon i

4条回答
  •  遥遥无期
    2020-12-15 13:00

    Prerequirements / Assumptions

    • You're on Windows (7, 8, 8.1)
    • You have a JDK installed at least in version 1.8.0 (javafx included)
    • You've set the JAVA_HOME environment variable pointing to the top directory of your JDK (ex. C:\Program Files\Java\jdk1.8.0_45)
    • You have Inno Setup at least in version 5.5.5 installed (prefered the unicode version)
    • You already have a icon file (256 x 256px), prefered a multisize one. I recommend to visit this site: http://icoconvert.com/
    • You already have a bmp file (48 x 48 px) for the setup installer as setup icon

    Solution

    Project structure

    First you need to setup the Project in a valid structure, like this: Your package folder have to be in the project root folder and not in any subfolder like src or resources.

    pom.xml

    There are some more properties needed for doing the correct deploy. As you can see in the antrun plugin section, you need to reassign the properties for your ant environment before you can call the build file. The properties are automatically set to the called build file. Normaly Intellij Idea will create the pom.xml for you in the project root dir.

    
    
        4.0.0
    
        com.autoap
        HelloWorld
        2.0
        jar
    
        
            UTF-8
            com.autoap.client.HelloWorld
            ${project.artifactId}
            Han Solo
        
    
        
            Star Wars
        
    
        
            
                
                    org.apache.maven.plugins
                    maven-dependency-plugin
                    2.6
                    
                        
                            unpack-dependencies
                            package
                            
                                unpack-dependencies
                            
                            
                                system
                                junit,org.mockito,org.hamcrest
                                ${project.build.directory}/classes
                            
                        
                    
                
                
                    org.codehaus.mojo
                    exec-maven-plugin
                    1.2.1
                    
                        
                            default-cli
                            
                                exec
                            
                            
                                ${java.home}/bin/java
                                -jar '${project.build.directory}/dist/${project.build.finalName}-${project.version}.jar'
                                
                            
                        
                    
                
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    3.1
                    
                        1.8
                        1.8
                    
                
    
                
                    maven-antrun-plugin
                    1.8
                    
                        
                            package
                            
                                
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                
                            
                            
                                run
                            
                        
                    
                
            
        
    
    
    

    build.xml

    I've tried to make it loosley coupled, so there is normaly no need to change anything in that file. Only if you want to have signing or special behaviour etc.The build.xml file should be saved in the project root dir.

    
    
    
    
    
        
    
            
            
                
                    
                    
                
            
    
            
            
    
    
            
    
    
            
            
                
            
    
            
            
                
                
                
            
    
            
    
                
                
    
                
                
    
                
                
    
                
                
    
                
                
    
                
                
            
    
        
    
        
        
            
            
    
            
                
                
            
        
    
        
        
            
            
        
    
    
    

    Images in package folder

    The images in your package folder need to be renamed. The icon file need to be exactly (case-sensitive) named as the property application.title in your maven pom. The second file is the setup icon, it need the exact application title as first part and -setup-icon.bmp the last part. It needs to be a bmp. Sizes mentioned above.

    My images looks like that:

    Run configuration

    The only thing you now need is to run the scripts to deploy it. For this you need a special run configuration like showing in the next screen:

    App

    After you have configured the run, run it and you will get the app. My App is nothing special only the default Hello World example and it looks like that:

    Path to exe installer

    In your project root is a folder target->dist->bundles, there you get your new Setup.exe

    Installer with icon

    Finally you got it.

    Target structure

    The target folder contains a non valid jar from the maven run, but it doesn't matter. You only should know, that if you only want the jar to start by double click, you need to choose the one in the dist folder. The jar in the dist folder is essential, because the whole process of creating an installer relies on this jar. Now you be also able to put a *.iss file in your package windows folder to customize more parts of the creation process, like a license file etc. For doing this, have a look here at the documention of Inno Setup.

提交回复
热议问题