JFinal框架使用undertow嵌入式web服务器打jar包运行

我的集成示例:https://gitee.com/a_seagull/jfinal-common

jfinal官方示例参考:https://jfinal.com/download/now?file=jfinal_demo_for_maven-5.0.0.zip

集成时可能出现如下问题:

maven-shade-plugin - Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer

这篇文章解决了我的问题:
https://github.com/spring-projects/spring-boot/issues/384

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/webapp</directory>
            <includes>
                <include>**/*</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/webapp</directory>
            <targetPath>webapp</targetPath>
        </resource>
    </resources>
    
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <encoding>UTF-8</encoding>
                    <compilerArgument>-parameters</compilerArgument>
                    <compilerArguments>
                        <verbose/>
                    </compilerArguments>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.artifactId}</finalName>
                            <transformers>

                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>

                                <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                                    <resource>META-INF/spring.factories</resource>
                                </transformer>

                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>

                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>[!注意这个标签的位置一定要放在这个位置,它是有顺序要求的]你自己项目的运行主类</mainClass>
                                </transformer>

<!--  下面的配置支持排除指定文件打包到 jar 之中,可以用于排除需要修改的配置文件以便于在外部的 config 目录下的同名配置文件生效,建议使用 Prop.appendIfExists(xxx_pro.txt) 在外部放一个非同名配置来覆盖开发环境的配置
则可以不用使用下面的配置,文档参考:http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#DontIncludeResourceTransformer  -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                                    <resources>
                                        <!-- <resource>demo-config-dev.txt</resource> -->
                                        <!-- <resource>.PDF</resource> -->
                                        <!-- <resource>READ.md</resource> -->
                                    </resources>
                                </transformer>
                                
                            </transformers>

<!--  解决 fatjar 的 "java.lang.SecurityException: Invalid signature file digest  for Manifest main attributes" 问题  -->
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

参考文章:https://www.codenong.com/49215416/

posted @ 2022-08-12 18:06  黄河大道东  阅读(332)  评论(0编辑  收藏  举报