maven插件Launch4j生成.exe运行没反应

把 gui 换成  console , 运行窗口会显示报了什么错,有个技巧,运行窗口一闪就消失了,可以使用鼠标在运行窗口点击一下,运行窗口就会暂停,点击空格或回车就会继续执行,就能方便看到报错信息。

我是在 idea 里建了一个工程,只有一个main方法的类,找不到main方法,所以无法运行,Launch4j的大概原理是 maven将 工程编译成jar,  Launch4j将jar转成 exe, 所以:

确保maven编译jar,这个jar的完整性,如果是springboot ,编译出的jar是完整的,包括了依赖,我正好是一个小工具,使用 java se  swing 写的,只有一个 main 方法,Maven的maven-jar-plugin插件只会将你的项目编译后的类文件打包进jar文件中,而不会包含项目的依赖库。为了包含项目的依赖库到jar中,你通常需要使用maven-assembly-pluginmaven-shade-plugin

所以我使用下面的编译插件:

 <build>
        <finalName>DateGenDecode</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version> <!-- 使用最新版本 -->
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.swkj.EnhancedEncryptionTool</mainClass>主启动类,一定要有包路径
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef> 编译完的jar包名称会拼上这个
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

 <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>2.4.1</version>
                <executions>
                    <execution>
                        <id>create-exe</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>gui</headerType> <!-- gui 或 console -->
                            <outfile>${project.build.directory}/${project.artifactId}.exe</outfile>
                            <jar>${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar</jar>  针对这个jar进行转成exe,jar名称后边是jar-with-dependencies,就是上边插件生成的名称
                            <errTitle>Error</errTitle>

                            <downloadUrl>http://java.com/download</downloadUrl>
                            <supportUrl>http://www.example.com/support</supportUrl>
                            <stayAlive>false</stayAlive>
                            <jre>
                                <bundledJreAsFallback>true</bundledJreAsFallback> <!-- 启用捆绑的 JRE 作为备选方案 -->
                                <minVersion>1.8.0</minVersion>
<!--                                <maxVersion>1.8.0</maxVersion>-->
                                <path>D:\java\jre1.8.0_101</path>
                                <maxHeapSize>128</maxHeapSize>
                            </jre>
                            <versionInfo>
                                <fileVersion>1.0.0.0</fileVersion>
                                <txtFileVersion>1.0.0.0</txtFileVersion>
                                <fileDescription>My Application</fileDescription>
                                <copyright>Copyright (C) 2024</copyright>
                                <productVersion>1.0.0.0</productVersion>
                                <txtProductVersion>1.0.0.0</txtProductVersion>
                                <productName>My Application</productName>
                                <internalName>myapp</internalName>
                                <originalFilename>myapp.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

这是遇到的坑,网上没怎么查到,特此记录,仅供参考。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值