fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.07k stars 133 forks source link

怎么能引入外部jar到当前项目打包中,类似spring-boot-maven-plugin的includeSystemScope #374

Closed curryPizza closed 1 year ago

curryPizza commented 1 year ago

I'm submitting a…

Short description of the issue/suggestion: 我的springboot项目中引入了三个外部jar包,打包时我通过additionalResources字段添加了jar包在系统中的路径,但启动时还是报了找不到文件的错误。

Steps to reproduce the issue/enhancement:

  1. [First Step]

image

  1. [Second Step]

image

What is the expected behavior?

What is the current behavior? 启动jar包时,找不到外部jar包中的类 image

Do you have outputs, screenshots, demos or samples which demonstrate the problem or enhancement? image

What is the motivation / use case for changing the behavior? 我尝试使用了spring-boot-maven-plugin打包的jar包可以正常启动。

Please tell us about your environment:

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

lhDream commented 1 year ago

Maven需要使用这种方式引入本地依赖

<dependency>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <systemPath>${project.basedir}/lib/test.jar</systemPath>
    <scope>system</scope>
</dependency>
fvarrui commented 1 year ago

Hi @curryPizza! Have you managed to fix this issue as @lhDream explained?

curryPizza commented 1 year ago

@lhDream 谢谢你的回复,但是我使用${project.basedir}作为路径还是显示在启动的时候找不到类

Hi @fvarrui

image

image

lhDream commented 1 year ago

@curryPizza 可以提供一下完整的配置么

如果你是spring boot项目可以加上这个配置

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <!--设置为true,以便把本地的system的jar也包括进来-->
        <includeSystemScope>true</includeSystemScope>
    </configuration>
</plugin>

一个 springBootDemo

lhDream commented 1 year ago

Hi @fvarrui , There seems to be no suitable way to introduce system lib in non-Spring boot projects.

Maybe we can refer to spring-boot-maven-plugin

curryPizza commented 1 year ago

@lhDream

我是springboot的项目,也引入了spring-boot-maven-plugin的配置,spring-boot-maven-plugin打包的jar包可以正常运行。(java -jar xx.jar运行) image

但是,javapackager生成的jar包显示缺外部资源包无法启动。(java -jar xx.jar运行)exe双击没反应,不清楚怎么生成log。

image

完整配置

<?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>io.github</groupId>
    <artifactId>stom9</artifactId>
    <version>1.0.0</version>

<!--    <repositories>-->
<!--        <repository>-->
<!--            <id>spring</id>-->
<!--            <url>https://maven.aliyun.com/repository/spring</url>-->
<!--            <releases>-->
<!--                <enabled>true</enabled>-->
<!--            </releases>-->
<!--            <snapshots>-->
<!--                <enabled>true</enabled>-->
<!--            </snapshots>-->
<!--        </repository>-->
<!--    </repositories>-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath/>

    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>8</java.version>
        <pagehelperVersion>4.1.6</pagehelperVersion>
        <spring.security.version>4.1.2.RELEASE</spring.security.version>
        <hutool-jwt.version>5.8.1</hutool-jwt.version>
        <javapackager.version>1.7.5</javapackager.version>
<!--        <mirrors>-->
<!--            <mirror>-->
<!--                <id>aliyunmaven</id>-->
<!--                <mirrorOf>*</mirrorOf>-->
<!--                <name>阿里云公共仓库</name>-->
<!--                <url>https://maven.aliyun.com/repository/public</url>-->
<!--            </mirror>-->
<!--        </mirrors>-->
    </properties>

    <dependencies>

        <!--本地jar,通用mapper,集成mybatis、druid、pagehelper分页-->
        <dependency>
            <groupId>com.github.peng</groupId>
            <artifactId>db-spring-boot-starter</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>system</scope>
<!--            <systemPath>${pom.basedir}/src/main/resources/lib/db-spring-boot-starter-1.0-SNAPSHOT.jar</systemPath>-->
            <systemPath>${project.basedir}/src/main/resources/lib/db-spring-boot-starter-1.0-SNAPSHOT.jar</systemPath>
        </dependency>
<!--        &lt;!&ndash;本地jar依赖&ndash;&gt;-->
        <dependency>
            <groupId>com.github.peng</groupId>
            <artifactId>db-spring-boot-autoconfigure</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>system</scope>
<!--            <systemPath>${pom.basedir}/src/main/resources/lib/db-spring-boot-autoconfigure-1.0-SNAPSHOT.jar</systemPath>-->
            <systemPath>${project.basedir}/src/main/resources/lib/db-spring-boot-autoconfigure-1.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-autoconfigure</artifactId>-->
<!--            <version>1.5.6.RELEASE</version>-->
<!--        </dependency>-->

        <!--本地jar依赖-->
        <dependency>
            <groupId>com.github.peng</groupId>
            <artifactId>common</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>system</scope>
<!--            <systemPath>${pom.basedir}/src/main/resources/lib/common-1.0-SNAPSHOT.jar</systemPath>-->
            <systemPath>${project.basedir}/src/main/resources/lib/common-1.0-SNAPSHOT.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.2</version>
        </dependency>
        <!-- jdbc -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>1.5.6.RELEASE</version>
        </dependency>
        <!-- Mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>
        <!-- 如果直接将实体里面所有的Date类型换成LocalDatetime之后,运行程序是会报异常的。此时,可以加入以下依赖:-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-typehandlers-jsr310</artifactId>
            <version>1.0.2</version>
        </dependency>
        <!-- Mybatis -->
        <!-- 分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.0.3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>1.5.6.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- 切换log4j2日志读取 -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
            <version>1.5.6.RELEASE</version>
        </dependency>

        <!-- Mysql 驱动
        https://blog.51cto.com/phyger/5276564 mysql 5及8
        -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>4.2.3.RELEASE</version>
        </dependency>

        <!--UI-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>Semantic-UI</artifactId>
            <version>2.2.10</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--log4j2-->
        <!--        &lt;!&ndash; 配置 log4j2 &ndash;&gt;-->
        <!--        <dependency>-->
        <!--            <groupId>org.springframework.boot</groupId>-->
        <!--            <artifactId>spring-boot-starter-log4j2</artifactId>-->
        <!--        </dependency>-->
        <!-- 加上这个才能辨认到log4j2.yml文件 -->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
        </dependency>

        <!--jWT-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-jwt</artifactId>
            <version>${hutool-jwt.version}</version>
        </dependency>
        <!-- jpa和redis -->
        <!--        <dependency>-->
        <!--            <groupId>org.springframework.boot</groupId>-->
        <!--            <artifactId>spring-boot-starter-data-jpa</artifactId>-->
        <!--        </dependency>-->
        <!--        <dependency>-->
        <!--            <groupId>org.springframework.boot</groupId>-->
        <!--            <artifactId>spring-boot-starter-data-redis</artifactId>-->
        <!--        </dependency>-->
        <!--        <dependency>-->
        <!--            <groupId>com.alibaba</groupId>-->
        <!--            <artifactId>fastjson</artifactId>-->
        <!--            <version>1.2.76</version>-->
        <!--        </dependency>-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>

        <!-- 引入redis依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <!-- 引入redis连接池的依赖 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>
        <!-- swagger -->
        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>1.9.0.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.9.9</version>
        </dependency>

        <!--rabbitmq java客户端-->
        <!--            <dependency>-->
        <!--                <groupId>com.rabbitmq</groupId>-->
        <!--                <artifactId>amqp-client</artifactId>-->
        <!--                <version>5.9.0</version>-->
        <!--            </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
            <version>2.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.78</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.3.24</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
        </dependency>
        <!-- 通用 Mapper -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
            <version>3.4.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.3.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>poi-ooxml-schemas</artifactId>
                    <groupId>org.apache.poi</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- 为了easyexcel -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>4.1.2</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>cglib</groupId>-->
<!--            <artifactId>cglib</artifactId>-->
<!--            <version>2.2</version>-->
<!--        </dependency>-->
        <!-- 为了easyexcel -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--        &lt;!&ndash; https://mvnrepository.com/artifact/org.apache.poi/poi &ndash;&gt;-->
        <!--        <dependency>-->
        <!--            <groupId>org.apache.poi</groupId>-->
        <!--            <artifactId>poi</artifactId>-->
        <!--            <version>3.15</version>-->
        <!--        </dependency>-->

        <!--        <dependency>-->
<!--            <groupId>org.apache.poi</groupId>-->
<!--            <artifactId>poi-ooxml</artifactId>-->
<!--            <version>4.1.0</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.apache.poi</groupId>-->
<!--            <artifactId>poi-ooxml-schemas</artifactId>-->
<!--            <version>4.1.0</version>-->
<!--        </dependency>-->
    </dependencies>
    <build>
        <resources>
            <resource><!--源-->
                <directory>src/main/resources/lib/</directory><!--你的文件所在路径-->
                <!--targetPath 指定打包到哪个目录下  默认是放到class目录下-->
                <targetPath>/BOOT-INF/lib/</targetPath>
                <includes><!--包含哪些后缀名文件-->
                    <include>**/*.jar</include>
                </includes>
            </resource>
            <resource><!--源-->
                <directory>src/main/resources/</directory><!--你的文件所在路径-->
                <includes><!--包含哪些后缀名文件-->
<!--                    <include>**/*.jar</include>-->
<!--                    <include>**/*.yml</include>-->
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!-- 将所有application开头的yaml文件排除,可以排除多个 -->
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>application*.yml</exclude>
                </excludes>
            </resource>

            <!-- 根据激活条件引入打包所需的配置文件,可以引入多个 -->
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application.yml</include>
                    <include>application-${environment}.yml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <!--            <plugin>-->
            <!--                <groupId>org.apache.maven.plugins</groupId>-->
            <!--                <artifactId>maven-compiler-plugin</artifactId>-->
            <!--                <version>3.5</version>-->
            <!--                <configuration>-->
            <!--                    &lt;!&ndash; put your configurations here &ndash;&gt;-->
            <!--                    <source>1.7</source>-->
            <!--                    <target>1.7</target>-->
            <!--                </configuration>-->
            <!--            </plugin>-->
            <!--            <plugin>-->
            <!--                <artifactId>maven-assembly-plugin</artifactId>-->
            <!--                <configuration>-->

            <!--                    <archive>-->
            <!--                        <manifest>-->
            <!--                            <mainClass>com.ysp.demo.DemoApplication</mainClass>-->
            <!--                        </manifest>-->
            <!--                    </archive>-->
            <!--                    <descriptorRefs>-->
            <!--                        <descriptorRef>jar-with-dependencies</descriptorRef>-->
            <!--                    </descriptorRefs>-->
            <!--                    <descriptor>src/main/assembly/assembly.xml</descriptor>-->
            <!--                </configuration>-->
            <!--                <executions>-->
            <!--                    <execution>-->
            <!--                        <id>make-assembly</id>-->
            <!--                        <phase>package</phase>-->
            <!--                        <goals>-->
            <!--                            <goal>single</goal>-->
            <!--                        </goals>-->
            <!--                    </execution>-->
            <!--                </executions>-->
            <!--            </plugin>-->

            <!--            <plugin>-->
            <!--                <groupId>org.mybatis.generator</groupId>-->
            <!--                <artifactId>mybatis-generator-maven-plugin</artifactId>-->
            <!--                <version>1.4.0</version>-->
            <!--                <executions>-->
            <!--                    <execution>-->
            <!--                        <id>Generate MyBatis Artifacts</id>-->
            <!--                        <goals>-->
            <!--                            <goal>generate</goal>-->
            <!--                        </goals>-->
            <!--                    </execution>-->
            <!--                </executions>-->
            <!--                <configuration>-->
            <!--                    &lt;!&ndash; 输出详细信息 &ndash;&gt;-->
            <!--                    <verbose>true</verbose>-->
            <!--                    &lt;!&ndash; 覆盖生成文件 &ndash;&gt;-->
            <!--                    <overwrite>true</overwrite>-->
            <!--                    &lt;!&ndash; 定义配置文件 &ndash;&gt;-->
            <!--                    <configurationFile>${basedir}/src/main/resources/generator-configuration.xml</configurationFile>-->
            <!--                </configuration>-->
            <!--            </plugin>-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.github.fvarrui</groupId>
                <artifactId>javapackager</artifactId>
                <version>1.7.5</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>package</goal>
                        </goals>
                        <configuration>
                            <platform>windows</platform>
                            <mainClass>com.ysp.demo.DemoApplication</mainClass>
                            <!-- optional -->

                            <bundleJre>true</bundleJre>
                            <jrePath>C:\Program Files\Java\jre1.8.0_181</jrePath>
                            <generateInstaller>true</generateInstaller>
                            <administratorRequired>false</administratorRequired>
                            <version>1.0</version>
                            <!-- 手动引入额外资源-->
                            <additionalResources>
                                <additionalResource>D:\workstation\lysp\src\main\resources\lib\common-1.0-SNAPSHOT.jar</additionalResource>
                                <additionalResource>D:\workstation\lysp\src\main\resources\lib\db-spring-boot-autoconfigure-1.0-SNAPSHOT.jar</additionalResource>
                                <additionalResource>D:\workstation\lysp\src\main\resources\lib\db-spring-boot-starter-1.0-SNAPSHOT.jar</additionalResource>
                            </additionalResources>
                            <platform>auto</platform>
                            <winConfig>
                                <wrapJar>false</wrapJar>
                            </winConfig>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                    <!-- 在打包时将引用的外部jar引入到当前项目包中 -->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>

<!--                <plugin>-->
<!--                    <groupId>cn.joylau.code</groupId>-->
<!--                    <artifactId>joylau-springboot-daemon-windows</artifactId>-->
<!--                    <version>1.1.RELEASE</version>-->
<!--                    <executions>-->
<!--                        <execution>-->
<!--                            <id>make-win-service</id>-->
<!--                            <phase>package</phase>-->
<!--                            <goals>-->
<!--                                <goal>make-win-service</goal>-->
<!--                            </goals>-->
<!--                        </execution>-->
<!--                    </executions>-->
<!--                </plugin>-->

        </plugins>
    </build>
    <!--    <pluginRepositories>-->
    <!--        <pluginRepository>-->
    <!--            <id>nexus</id>-->
    <!--            <name>nexus-snapshot-repository</name>-->
    <!--            <url>https://oss.sonatype.org/content/repositories/snapshots</url>-->
    <!--            <snapshots>-->
    <!--                <enabled>true</enabled>-->
    <!--                <updatePolicy>always</updatePolicy>-->
    <!--            </snapshots>-->
    <!--            <releases>-->
    <!--                <enabled>false</enabled>-->
    <!--            </releases>-->
    <!--        </pluginRepository>-->
    <!--    </pluginRepositories>-->
    <!-- 环境配置 -->
    <profiles>
    <profile>
        <!-- 环境id -->
        <id>dev</id>
        <activation>
            <!-- 是否默认启用 -->
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <!-- 环境标签变量,在yaml中会被用到 -->
            <environment>dev</environment>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <environment>prod</environment>
        </properties>
    </profile>
    </profiles>
</project>
lhDream commented 1 year ago

@curryPizza 可以参考以下配置,先用 spring-boot-maven-plugin生成jar,再将spring-boot-maven-plugin生成的jar打包为exe

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <!--设置为true,以便把本地的system的jar也包括进来-->
                <includeSystemScope>true</includeSystemScope>
            </configuration>
        </plugin>
        <plugin>
            <groupId>io.github.fvarrui</groupId>
            <artifactId>javapackager</artifactId>
            <version>1.7.5</version>
            <executions>
                <execution>
                    <id>bundling-for-windows</id>
                    <phase>package</phase>
                    <goals>
                        <goal>package</goal>
                    </goals>
                    <configuration>
                        <platform>windows</platform>
                        <!-- 文件说明 -->
                        <displayName>your display name</displayName>
                        <!--打包后exe名称-->
                        <name>yourAppName.exe</name>
                        <!-- 启动类 (Spring Boot固定写法,而不是自己的main函数所在类) -->
                        <mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
                        <!-- 虚拟机参数 -->
                        <vmArgs>
                            <arg>-Xms256M</arg>
                            <arg>-Xmx512M</arg>
                        </vmArgs>
                        <!-- optional -->
                        <!-- 是否将jvm一起打包到程序中 -->
                        <bundleJre>true</bundleJre>
                        <!--定制jre, java8不支持定制-->
                        <customizedJre>false</customizedJre>
                        <jrePath>C:\Program Files\Java\jre1.8.0_181</jrePath>
                        <copyDependencies>false</copyDependencies>
                        <!--是否打包安装包-->
                        <generateInstaller>true</generateInstaller>
                        <forceInstaller>true</forceInstaller>
                        <!-- 其他插件生成的jar名称,这里指的是 spring-boot-maven-plugin -->
                        <runnableJar>${project.build.directory}/${project.name}-${project.version}.jar</runnableJar>
                        <winConfig>
                            <headerType>console</headerType>
                            <icoFile>${project.basedir}/src/main/resources/imgs/logo.ico</icoFile>
                        </winConfig>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
curryPizza commented 1 year ago

@lhDream 十分感谢!通过这个方法双击exe可以运行了。但是在进程管理器中,这个程序显示的是

image

如何能够显示程序名,我的配置如下

                            <winConfig>
                                <generateSetup>true</generateSetup>
                                <productName>${project.name}</productName>
                                <internalName>${project.name}</internalName>
                                <fileDescription>${project.description}</fileDescription>
                                <wrapJar>false</wrapJar>
                            </winConfig>

另外,想请教一下

  1. 是否支持打包mysql、redis、mq、nginx等环境,能实现一键安装
  2. 是否支持输出日志

谢谢!

lhDream commented 1 year ago

@curryPizza 关于进程名称这个问题,launch4j打包的名称问题目前还没解决,在不同电脑上显示的不一致,有时候是进程名称,有时候是 java,可以使用其他打包方式: winrun4j | why

<winConfig>
    <exeCreationTool>winrun4j | why</exeCreationTool>
</winConfig>

至于打包 MySQL、Redis这些自然是可以的,可以将这些程序目录作为资源文件加入,但安装后启动则需要你自己写脚本实现; 建议你看看 Inno Setup相关文档

curryPizza commented 1 year ago

@lhDream okok,无敌无敌感谢,我研究下。

forqsg commented 8 months ago

打包linux安装器deb的时候,怎么样可以通过additionalResource指定资源文件捆绑打包出来后,可以放自定义的文件夹中。其中该文件夹能通过指定生成的,并且是包含在deb安装器安装后的主目录下。这种可以实现吗?因为我看到使用additionalResource进行资源捆绑时,所指定的资源文件是直接打包放到到主目录下的,没有看到能放到自己指定的某个文件夹中。

lhDream commented 8 months ago

@forqsg 目录结构提前弄好再引入