How to get the JRE to bundle with launch4j?

前端 未结 2 955
死守一世寂寞
死守一世寂寞 2021-01-02 19:39

I understand that launch4j doesn\'t bundle the JRE in the .exe but that you have to place it next to it. My question is, how am I supposed to do that? Is there

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 19:56

    UPDATE: Deleted my previous answer and replacing with tested working example

    UPDATE 2: This pom.xml now downloads the JRE tgz and unpacks it and the launch4j exe uses it and it works. I added comments to explain how it works.

    I would recommend sticking with just a 32 bit exe and JRE. The only reason to use the 64 bit JRE would be if your program needs to use more than 4 GB of RAM.

    Of course now you need an installer that takes all this and installs to Program Files. I've used NSIS for this in the past. There is a learning curve for NSIS but it is not too bad.

    
    
        4.0.0
        com.akathist.encc
        mavenproject1
        1.0-SNAPSHOT
        jar
        
            UTF-8
            1.8
            1.8
        
        
            
            
                com.oracle.java
                jre
                win32
                tgz
                1.8.0_131
            
        
        
            
                
                alfresco
                https://artifacts.alfresco.com/nexus/content/repositories/public/
            
        
        
            
                
                    
                    org.apache.maven.plugins
                    maven-dependency-plugin
                    2.5.1
                    
                        
                            generate-resources
                            
                                unpack-dependencies
                            
                            
                                com.oracle.java
                                tgz
                                jre
                                win32
                                target/win32
                            
                        
                    
                
                
                    
                    com.akathist.maven.plugins.launch4j
                    launch4j-maven-plugin
                    
                        
                            l4j-clui
                            package
                            
                                launch4j
                            
                            
                                console
                                target/encc.exe
                                target/mavenproject1-1.0-SNAPSHOT.jar
                                encc
                                
                                    com.akathist.encc.Clui
                                    false
                                    anything
                                
                                
                                    ./win32/java
                                
                                
                                    1.2.3.4
                                    txt file version?
                                    a description
                                    my copyright
                                    4.3.2.1
                                    txt product version
                                    E-N-C-C
                                    ccne
                                    original.exe
                                
                            
                        
                    
                
            
        
    
    

    UPDATE 3: The sad fact is that there exists no offical or even up-to-date maven repo with the JREs that you want. You could host your own maven repo that has the desired JREs. You will have to update this as new releases are done. It is also a good idea to test with the new version before releasing with it. The third Tuesday of every month is when new Java releases are done. You can set a reminder for this to check if a new version was released and download it. Automating this is a pain because of the license agreement check. This post might help but you probably can't download the tar.gz version of the JRE this way: Java check latest version programmatically

    If you want to support multiple platforms then hosting your own maven repo is a good way to go. You can host your own repo and update it with the new JRE tar.gz every time a release is done with this: https://stackoverflow.com/a/29261502/35264

    The simplest option is to do what you were aiming for already and just use the JRE that you are building with. This will allow you to support Windows 32 and 64 as long as you build with the 32 bit JRE. You can update this occasionally as you have time to test with the new version. Here is a working pom.xml that does this:

    
    
        4.0.0
        com.akathist.encc
        mavenproject1
        1.0-SNAPSHOT
        jar
        
            UTF-8
            1.8
            1.8
        
        
            
                
                    
                    maven-resources-plugin
                    2.6
                    
                        
                            copy-resources
                            
                            package
                            
                                copy-resources
                            
                            
                                ${basedir}/target/win32/java
                                
                                    
                                        ${java.home}
                                    
                                
                            
                        
                    
                
                
                    
                    com.akathist.maven.plugins.launch4j
                    launch4j-maven-plugin
                    
                        
                            l4j-clui
                            package
                            
                                launch4j
                            
                            
                                console
                                target/encc.exe
                                target/mavenproject1-1.0-SNAPSHOT.jar
                                encc
                                
                                    com.akathist.encc.Clui
                                    false
                                    anything
                                
                                
                                    ./win32/java
                                
                                
                                    1.2.3.4
                                    txt file version?
                                    a description
                                    my copyright
                                    4.3.2.1
                                    txt product version
                                    E-N-C-C
                                    ccne
                                    original.exe
                                
                            
                        
                    
                
            
        
    
    

提交回复
热议问题