目录

建立方式

创建之前

修改maven

指定本机的仓库位置

添加加速镜像

新建项目

修改pom.xml

建立代码文件夹

建立common包

建立配置类AppConfig.java

建立启动配置文件undertow.properties

建立首页

启动项目


建立方式

建立JFinal项目两种方式,一种是通过官方网站文档(https://jfinal.com/doc),另一个是使用JBolt(http://www.jbolt.cn)的eclipse插件。

使用JBolt插件可以快速生成一个带首页、有数据库配置的web项目。可以在创建前选择需要的内容,如数据库选择(支持Mysql/Oracle/Sql Server/H2/Sqlite/PostgreSql),server选择(支持undertow/jetty/tomcat/other),libs的选择(如hutool/Ehcache/POI/ZXing/Shiro/Jfinal-wexin等),但它不是一个平台,只是快速建立web项目的工具。

官方文档中如何建立项目说的很清楚,一步一步操作即可。只是官方是使用mac os下的eclipse,本次在windows下使用idea创建maven项目来进行操作。

创建之前

修改maven

本例中没有使用idea自带的maven,而是下载了apache的maven,并且修改了仓库的位置:D:\java\apache-maven-3.6.3\conf\settings.xml

指定本机的仓库位置

<localRepository>D:/Java/mavenrepo/repository</localRepository>

添加加速镜像

<mirror><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

新建项目

自动生成了部分内容,需要修改pom.xml

修改pom.xml

<packaging>war</packaging>

改为

<packaging>jar</packaging>

修改编译环境为1.8

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

添加仓库

  <!-- 使用阿里 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>

添加依赖

<dependency><groupId>com.jfinal</groupId><artifactId>jfinal-undertow</artifactId><version>2.4</version>
</dependency><dependency><groupId>com.jfinal</groupId><artifactId>jfinal</artifactId><version>4.9.06</version>
</dependency>

打包配置(自动生成plugns的内容可以删除替换成以下代码)

注意要将<pluginManagement>和</pluginManagement>删除掉,否则无法打成zip文件

<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.6.1</version><configuration><source>1.8</source><target>1.8</target><encoding>utf-8</encoding><!-- java8 保留参数名编译参数 --><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>2.6</version><configuration><excludes><exclude>*.txt</exclude><exclude>*.xml</exclude><exclude>*.properties</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.1.0</version><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals><configuration><!-- 打包生成的文件名 --><finalName>${project.artifactId}</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></plugins>

需要在pom.xml同目录下建立package.xml

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"><!--assembly 打包配置更多配置可参考官司方文档:http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html--><id>release</id><!--设置打包格式,可同时设置多种格式,常用格式有:dir、zip、tar、tar.gzdir 格式便于在本地测试打包结果zip 格式便于 windows 系统下解压运行tar、tar.gz 格式便于 linux 系统下解压运行--><formats><format>dir</format><format>zip</format></formats><!-- 打 zip 设置为 true 时,会在 zip 包中生成一个根目录,打 dir 时设置为 false 少层目录 --><includeBaseDirectory>true</includeBaseDirectory><fileSets><!-- src/main/resources 全部 copy 到 config 目录下 --><fileSet><directory>${basedir}/src/main/resources</directory><outputDirectory>config</outputDirectory></fileSet><!-- src/main/webapp 全部 copy 到 webapp 目录下 --><fileSet><directory>${basedir}/src/main/webapp</directory><outputDirectory>webapp</outputDirectory><excludes><exclude>WEB-INF</exclude><exclude>WEB-INF/web.xml</exclude></excludes></fileSet><!-- 项目根下面的脚本文件 copy 到根目录下 --><fileSet><directory>${basedir}</directory><lineEnding>unix</lineEnding><outputDirectory></outputDirectory><!-- 脚本文件在 linux下的权限设为755,无需chmod可直接运行 --><fileMode>755</fileMode><includes><include>*.sh</include></includes></fileSet><fileSet><directory>${basedir}</directory><lineEnding>windows</lineEnding><outputDirectory></outputDirectory><fileMode>755</fileMode><includes><include>*.bat</include></includes></fileSet></fileSets><!-- 依赖的 jar 包 copy 到 lib 目录下 --><dependencySets><dependencySet><outputDirectory>lib</outputDirectory></dependencySet></dependencySets></assembly>

重新加载maven的改变

建立代码文件夹

在main目录下建立java和resources

建立common包

可以取消包的合并

建立配置类AppConfig.java

继承JFinalConfig,导入相关methods

源码:

package cc.onthis.common;import com.jfinal.config.*;
import com.jfinal.template.Engine;public class AppConfig extends JFinalConfig {@Overridepublic void configConstant(Constants me) {// true=开发模式me.setDevMode(true);}@Overridepublic void configRoute(Routes me) {// 如果要将控制器超类中的 public 方法映射为 action 配置成 true,一般不用配置me.setMappingSuperClass(false);// 配置 baseViewPath,可以让 render(...) 参数省去 baseViewPath 这部分前缀me.setBaseViewPath("/view");// 使用路由扫描,参数 "cc.onthis." 表示只扫描 demo 包及其子包下的路由me.scan("cc.onthis.");}@Overridepublic void configEngine(Engine me) {}@Overridepublic void configPlugin(Plugins me) {}@Overridepublic void configInterceptor(Interceptors me) {}@Overridepublic void configHandler(Handlers me) {}
}

创建启动类Application.java

public static void main(String[] args) {UndertowServer.create(AppConfig.class,"undertow.properties").start();
}

AppConfig.class是刚才建立的配置类

undertow.properties是配置文件,需要在resources中建立该文件

建立启动配置文件undertow.properties

# 常用配置
# true 值支持热加载 生产环境建议配置成 false
undertow.devMode=true
# 项目端口
undertow.port=80
undertow.host=0.0.0.0
# 绝大部分情况不建议配置 context path
#undertow.contextPath=/# web 资源加载路径配置
undertow.resourcePath = src/main/webapp, classpath:webapp# 开启 gzip 压缩
undertow.gzip.enable=true
# 配置压缩级别,默认值 -1。 可配置 1 到 9。 1 拥有最快压缩速度,9 拥有最高压缩率
undertow.gzip.level=-1
# 触发压缩的最小内容长度
undertow.gzip.minLength=1024

建立首页

创建包与文件

启动项目

打开Application.java,右键选择debug

显示如下即为成功

打开浏览器,录入http://localhost

源码:https://download.csdn.net/download/farce/14122721

JFinal建立项目相关推荐

  1. 《Adobe Premiere Pro CC经典教程(彩色版)》——2.2 建立项目

    本节书摘来自异步社区<Adobe Premiere Pro CC经典教程(彩色版)>一书中的第2课,第2.2节,作者 [英国]Maxim Jago(马克西姆 亚戈),译者 陈昕昕,郭光伟 ...

  2. ServiceStack 项目实例 001 建立项目结构

    ServiceStack 用于服务开发,可以为各种形式的网站.软件.APP等提供数据服务,可以提供REST,WebService以及二级制数据形式的服务. 下面根据我们具体项目要求,说一下建立项目的方 ...

  3. 安卓(android)建立项目时失败,出现Android Manifest.xml file missing几种解决方法?...

    安卓(android)建立项目时失败,出现AndroidManifest.xml file missing几种解决方法? Eclipse新建项目,遇到这样的问题,注意如下: 1.文件名最好不要用中文. ...

  4. cocos2d-x win8下的环境配置和建立项目

    cocos2dx 跨平台.可是看网上说开发最合适还是在vs2010中,基本是编完后再移植到安卓. 1.去官网下载源代码2.2.3版本号的. 2.然后运行根文件夹下的build-win32.bat(须要 ...

  5. spring boot建立项目 git推送giteee

    gitee上创建项目时候不要创建readme.md   创建完全空的项目  不然上次会报错的 $ git init    初始化git $ git status    $ git add .     ...

  6. 02-Flutter移动电商实战-建立项目和编写入口文件

    02-Flutter移动电商实战-建立项目和编写入口文件 环境搭建请参考之前写的一篇文章:Flutter_初体验_创建第一个应用 1.创建项目 采用AndroidStudio构建本项目,FIle> ...

  7. 建立项目接口文档_分享:一步一个脚印,vue入门之使用mockjs搭建vue项目测试服务器...

    在以前的文档中,我们构建了vue项目的整体架构,详见vue入门:vue项目架构设计起步,现在我们主要对其中的mock server 进行完善. 一.概述 前后端分离的项目优点之一就是可以前后端并行开发 ...

  8. 安卓(android)建立项目时失败,出现Android Manifest.xml file missing几种解决方法?(总结中)

    安卓(android)建立项目时失败,出现Android Manifest.xml file missing几种解决方法?(总结中) 参考文章: (1)安卓(android)建立项目时失败,出现And ...

  9. GitHub使用(1):从GitHub建立项目分支并克隆到本地

    目录 一.概述 二.从GitHub建立项目分支并克隆到本地 2.1 GitHub创建分支 2.2 本地克隆 三.GitHub和本地仓库关联使用 3.1 本地修改 3.2 推送本地到远程 3.3 更新远 ...

最新文章

  1. 受损骨骼可能在类似地球的重力条件下更快愈合
  2. 在GridView里使用上下箭头(小键盘旁边)来选择记录
  3. idea ctrl+shift+f快捷键失效
  4. 备考一天速通计算机三级网络技术
  5. 国外常用的jQuery响应式网页模板
  6. Exp3 免杀原理与实践 20164314
  7. Linux 生产者消费者简单例子学习
  8. python与office结合可以干什么-Python 进行Office开发(以Word为例)
  9. Java深入了解TreeSet,和迭代器遍历方法
  10. 【算法学习】将MSRCR中的模糊处理由FFT修改为时域纯高斯模糊
  11. win10更新后开不了机_坚决不更新!被微软雪藏的win10系统版本,只要3GB,老爷机的克星!...
  12. 服务器专用影子系统,试试最牛X的影子系统!瞬间创建N个账号
  13. 计算机动漫与游戏制作电脑配置,动漫与游戏设计该如何选电脑配置?
  14. 396万奖金池!视觉特征编码、AI+无线通信两大赛道等你来战!助力元宇宙!
  15. 详细的苹果快捷键,赶快保存吧!
  16. 蓝牙、红外线与wifi 区别以及不同频段无线电磁波的穿墙和绕过障碍物能力
  17. 英语学习中总结的阅读、段落匹配、选词填空技巧
  18. MessageFilter [target=odom ]: Dropped 95.28% of messages so far.Please turn the [ros.gmapping.messag
  19. Ubuntu新手-谈第一次在Ubuntu升级VMware Tolls
  20. 118 以太坊 ethereum hardhat :编译 artifacts

热门文章

  1. MySQL 解析单条查询
  2. 米思齐学习例程(十):做一个门铃
  3. squid和squidGuard配置代理服务器
  4. 冒险岛的服务器维护时间,冒险岛官方网站(MapleStory)-爱我就来冒险吧!
  5. Java使用RXTX进行串口SerialPort通讯
  6. 用python画一条龙_树莓派打造北邮人种子下载机——下载、做种一条龙全站式教程...
  7. 求助与探讨:如何规划我的职业生涯
  8. Debian7.1下Broadcom 4312无线网卡驱动安装
  9. 做不下去了,就开心一下吧。
  10. ChatGPT 中文 Prompt 提示词,常用、高频集合