JFinal使用技巧-JAVA21运行demo

应社友分享JAVA21下运行JF项目,各种借口已经拖更了一周。。。实在抱歉~ 

时间还是有点仓促,就使用 官方的 JFinal demo for maven 5.0.0  做为例子了。

0、下载最新版本的 idea【 https://jfinal.com/share/2728 前面也有分享教程(下载安装就行,最新版 idea 不用插件了) 

1、下载并运行成功demo,项目默认是 JAVA8 的,这个大家应该是能跑起来的。解压、idea 打开、里面有启动文档说明。
2、下载 JDK21 是必要的【https://www.oracle.com/java/technologies/downloads/?er=221886#jdk21-mac  】

3、修改项目的运行环境:image.pngimage.png

4、修改 pom.xml 文件配置参数:(主要是 plugins 里面的版本需要升级

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    
    <groupId>com.demo</groupId>
    <artifactId>jfinal_demo_for_maven</artifactId>
    <version>5.0.0</version>
    <packaging>jar</packaging>
    
    
    <name>jfinal_demo_for_maven</name>
    
    <url>https://jfinal.com/user/1</url>
    
    <properties>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
       <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    </properties>
    
    <!-- 使用阿里 maven 库 -->
    <repositories>
       <repository>
          <id>ali-maven</id>
          <url>http://maven.aliyun.com/nexus/content/groups/public</url>
          <releases>
             <enabled>true</enabled>
          </releases>
          <snapshots>
             <enabled>true</enabled>
             <updatePolicy>always</updatePolicy>
             <checksumPolicy>fail</checksumPolicy>
          </snapshots>
       </repository>
    </repositories>
    
    <!-- 添加快照版本库,updatePolicy: always、daily、interval、never -->
    <!-- repositories>
       <repository>
          <id>sonatype-nexus-snapshots</id>
          <name>Sonatype Nexus Snapshots</name>
          <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
          <releases>
             <enabled>false</enabled>
          </releases>
          <snapshots>
             <enabled>true</enabled>
             <updatePolicy>daily</updatePolicy>
          </snapshots>
       </repository>
    </repositories -->
    
    <dependencies>
    
       <!-- jfinal -->
       <dependency>
          <groupId>com.jfinal</groupId>
          <artifactId>jfinal</artifactId>
          <version>5.2.2</version>
       </dependency>

       <!-- jfinal-undertow 开发、部署一体化 web 服务器 -->
       <dependency>
          <groupId>com.jfinal</groupId>
          <artifactId>jfinal-undertow</artifactId>
          <version>3.6</version>
       </dependency>
       
       <!-- cos 文件上传 -->
       <dependency>
          <groupId>com.jfinal</groupId>
          <artifactId>cos</artifactId>
          <version>2022.2</version>
       </dependency>

       <!-- junit 单元测试 -->
       <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.13.2</version>
          <scope>test</scope>
       </dependency>
       
       <!-- 避免控制台输出如下提示信息:
           SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
           项目中实际上用不到这个 jar 包,本 jfinal demo 用不上这个依赖,在此仅为大家
           在未来基于 jfinal demo 为模板做开发时做准备工作
           注意:eclipse 下可以将 scope 设置为 provided
       -->
       <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-nop</artifactId>
          <version>1.7.29</version>
          <!-- 打包前改成 provided,此处使用 compile 仅为支持 IDEA -->
          <scope>compile</scope>
       </dependency>
       
       <!-- log4j 日志 -->
       <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.17</version>
       </dependency>
       
       <!-- mysql 驱动 -->
       <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.49</version>
       </dependency>
       
       <!-- druid 数据源连接池 -->
       <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>1.0.29</version>
       </dependency>
    
    </dependencies>
    
    <build>
       
       
       <!--
           添加 includes 配置后,excludes 默认为所有文件 **/*.*,反之亦然
           该规则在 maven-jar-plugin 等插件中同样适用
       -->
       <resources>
          <!-- 添加该配置是为了将 .sql 文件打入 jar 包 -->
          <resource>
             <directory>src/main/java</directory>
             <includes>
                <!-- **/* 前缀用法,可以匹配所有路径 -->
                <include>**/*.sql</include>
             </includes>
          </resource>
          
          <!--
             没有添加 resources 配置时,src/main/resources 目录是默认配置
              一旦添加 resources 配置指向 src/main/java 目录时,原先的默认配置被取代,
              所以需要添加如下配置将默认配置再添加进来,否则无法使用 src/main/resources
              下的资源文件
          -->
          <resource>
             <directory>src/main/resources</directory>
          </resource>
       </resources>



       <plugins>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <version>3.9.0</version>
             <configuration>
                <source>21</source>
                <target>21</target>
                <encoding>UTF-8</encoding>
                <!-- 保留参数名编译参数 -->
                <compilerArgument>-parameters</compilerArgument>
                <compilerArguments><verbose /></compilerArguments>
             </configuration>
          </plugin>

          <!--
             jar 包中的配置文件优先级高于 config 目录下的 "同名文件"
             因此,打包时需要排除掉 jar 包中来自 src/main/resources 目录的
             配置文件,否则部署时 config 目录中的同名配置文件不会生效
           -->
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-jar-plugin</artifactId>
             <version>3.3.0</version>
             <configuration>
                <excludes>
                   <exclude>*.txt</exclude>
                   <exclude>*.xml</exclude>
                   <exclude>*.properties</exclude>
                   <exclude>upgrade_sql/*</exclude>
                </excludes>
             </configuration>
          </plugin>

          <!--
             使用 mvn clean package 打包
             更多配置可参考官司方文档:http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html
          -->
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-assembly-plugin</artifactId>
             <version>3.6.0</version>
             <executions>
                <execution>
                   <id>make-assembly</id>
                   <phase>package</phase>
                   <goals>
                      <goal>single</goal>
                   </goals>

                   <configuration>
                      <!-- 打包生成的文件名 -->
                      <finalName>app</finalName>
                      <!-- jar 等压缩文件在被打包进入 zip、tar.gz 时是否压缩,设置为 false 可加快打包速度 -->
                      <recompressZippedFiles>false</recompressZippedFiles>
                      <!-- 打包生成的文件是否要追加 release.xml 中定义的 id 值 -->
                      <appendAssemblyId>true</appendAssemblyId>
                      <!-- 指向打包描述文件 package.xml -->
                      <descriptors>
                         <descriptor>package.xml</descriptor>
                      </descriptors>
                      <!-- 打包结果输出的基础目录 -->
                      <outputDirectory>${project.build.directory}/</outputDirectory>
                   </configuration>
                </execution>
             </executions>
          </plugin>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-javadoc-plugin</artifactId>
             <version>3.6.0</version>
          </plugin>
       </plugins>
    </build>
    
</project>


5、配置完成,刷新一下 maven,启动项目!!!

image.png

image.png

启动完成:
image.pngimage.png

中秋再分享 ThreadPoolKit 、ScheduledKit 两个宝贝工具类~ (先水一篇~)


评论区

JFinal

2024-09-15 12:03

先赞后看

北流家园网

2024-09-16 22:40

收藏收藏

热门分享

扫码入社