fatjar 打包(全部打包到一个jar)

fatjar 打包(全部打包到一个jar)
=====================================================================
1、在 AppConfig 中的 configEngine(Engine me) 方法中添加如下两行代码
    me.setBaseTemplatePath("webapp");
    me.setToClassPathSourceFactory();
---------------------------------------------------------------------
2、在 undertow.txt 配置文件中添加如下配置:
   undertow.resourcePath=src/main/webapp, classpath:webapp
---------------------------------------------------------------------
3、在 pom.xml 配置文件中添加如下配置:
<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>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
                <compilerArgument>-parameters</compilerArgument>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes/webapp</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/webapp</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>app.config.AppConfig</mainClass>
                                <!-- 修改成自己的程序入口 -->
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

---------------------------------------------------------------------
4、打包
   mvn clean package
---------------------------------------------------------------------
5、运行
   java -jar jfinal-demo.jar
   启动(后台启动)
   nohup java -jar xxx.jar &


评论区

JFinal

2024-08-09 12:17

jfinal-club.zip 中有一个目录,里面也介绍了打成一个 jar 包的方法,还给出了 pom.xml

热门分享

扫码入社