使用 IDEA 开发 GAPP
导入源代码项目
- 打开 IDEA,选择 Open... ,选择在 GDK 控制台 中创建的应用项目的目录路径,点击 “Open” 按钮打开项目,完成导入。
注意
由于 IDEA 默认情况下,对 Maven 的支持不够完整,某些选项默认不开启,以及不执行 Maven 插件的某些生命周期行为,所以无法在导入后自动完成项目设置,需要一些额外的手工配置。
手动构建项目
- 由于IDEA对于自动构建插件支持的不完善,所以这里需要我们手工去生成启动类,
注意
- 默认情况,IDEA 在导入或创建新项目时,都会重置 Maven 配置( Settings > Build,Execution,Deployment > Build Tools > Maven ) ,而不是延续上一个项目的设置,也不会自动采用环境变量
M2_HOME
指向的 Maven 安装环境的配置。- 因此,在导入或创建新项目后,需要先检查 IDEA 中的 Maven 进行配置,确保采用了系统环境变量
M2_HOME
指向的正确配置,而不是 IDEA 自身提供的默认配置。- 建议将 IDEA 的 Maven 配置属性
Maven home path
设置为$M2_HOME
环境变量的实际值,将User settings file
设置为$M2_HOME/conf/settings.xml
。 (注意:IDEA 不识别$M2_HOME
环境变量,请用实际的值替换)- 关于 Maven 环境的配置,请参考 《配置 Maven》
- 手动执行 Maven 编译命令
点击 Maven 选项卡,选择命令窗口,输入 mvn clean package
命令执行编译构建任务。
GAPP 项目结构
项目构建过程中,后端项目的 pom.xml 引入的com.linkgie.galaxytools.plugins:galaxy-app-plugin
插件会自动生成 GAPP 项目的启动类。
当完成构建后, GAPP 项目最终的目录结构如下:
ROOT # 应用源码项目根目录 |—— .gitignore # git 忽略规则文件 |—— .gprj # gapp 项目元数据文件 |—— pom.xml # 根模块的 Maven 配置文件 | |—— server # 服务端模块的项目目录 | |—— pom.xml # 服务端模块的 Maven 配置文件 | |—— src # 服务端模块的源代码目录 | | |—— main # 主源代码目录 | | | |—— java # java 源代码目录 | | | |__ resources # 资源目录 | | | |—— conf # 应用的配置文件目录; | | | | |—— server.conf # 应用的服务配置文件; | | | | |__ log4j2.xml # 应用的日志配置文件; | | | | | | | |__ profiles # 应用的功能菜单配置目录; | | | |—— application.profile # 主功能菜单配置(必须); | | | |__ other.profile # 其它功能菜单配置,可选; | | | | | |__ test # 测试源代码目录 | | | |__ auto-src # 进行了编译后才自动生成的源代码目录 | |__ ui # 前端模块的项目目录 |—— pom.xml # 前端模块的 Maven 配置文件 |__ ${appCode}-ui # 前端项目目录(npm + vite 工程), | # 项目目录由“应用编码” + 后缀“-ui” 命名 | |—— package.json # npm 工程配置文件; |—— vite.config.js # vite 构建配置文件; |__ src # 前端源代码目录
手动标记的源码目录
选择后端项目 server
目录下的 auto-src
目录,右键,在菜单中选择 “Mark Directory as” 菜单的下级子菜单 “Generated Sources Root” ,在 IDEA 中将该目录标记为源码目录,这样自动生成的启动类才能够被执行。
由于 IDEA 不支持执行项目的 pom.xml 配置指定的 Maven 插件
generate-sources
生命期,因此,尽管com.linkgie.galaxytools.plugins:galaxy-app-plugin
插件会自动地在 Maven 上下文将auto-src
目录设置为源码目录,但也无法使得 IDEA 将该目录自动标记为源码目录。
完成标记后, auto-src
目录显示了源码目录的标志。
运行/调试
启动
- 运行模式 IDE 中,选择启动器类,在右键菜单中选择运行 “Run ‘MyappBooter.main()’”。
- 调试模式 IDE 中,选择启动器类,在右键菜单中选择运行 “Debug ‘MyappBooter.main()’”。
Run ‘MyappBooter.main()’ 中的 MyappBooter 是启动器类型的名称,该名称与应用的编码一致,可以在项目的
pom.xml
中修改 。
启动后,控制台日志输出如下:
booting...
------------------ Galaxy Web Server[2.8.0-SNAPSHOT] starts at [2024-03-21 19:28:20.547]...... ------------------
Start initializing the Application HomeContext at directory[/Users/spring/Documents/develop/workspace-galaxy/mygapp/server/target] ...
Initializing home [application.home]=[/Users/spring/Documents/develop/workspace-galaxy/mygapp/server/target]
Start initializing the Application HomeContext at directory[/Users/spring/Documents/linkgie/gits/galaxy-system/galaxy-middleware/gdk/target/gdk-2.8.0-SNAPSHOT-20240320561010] ...
初始化应用[Lowcode-Development-Platform]...
Galaxy Web Server starts with configuration[classpath:/conf/server.conf]
2024-03-21 19:28:21.507 INFO 34173 --- [ Thread-3] o.s.b.SpringApplication :
·
:::::::: ::: ::: ::: ::: ::: ::: :::
:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
:#: +#++:++#++: +#+ +#++:++#++: +#++:+ +#++:
+#+ +#+# +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+# #+# #+# #+#
######## ### ### ########## ### ### ### ### ###
::::: ::: ::::: ::: ::::: ::: ::::: ::: ::::: ::: ::::: :::
:+: :+:+: :+: :+:+: :+: :+:+: :+: :+:+: :+: :+:+: :+: :+:+:
----------------------
Powered By Linkgie.COM
----------------------
2024-03-21 19:28:21.561 INFO 34173 --- [ Thread-3] o.s.b.SpringApplication : Starting application using Java 1.8.0_212 on SpringdeMacBook-Pro.local with PID 34173 (started by spring in /Users/spring/Documents/develop/workspace-galaxy/mygapp/server)
2024-03-21 19:28:21.658 INFO 34173 --- [ Thread-3] o.s.b.SpringApplication : No active profile set, falling back to default profiles: default
2024-03-21 19:28:23.822 INFO 34173 --- [ Thread-3] o.s.b.w.e.t.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2024-03-21 19:28:24.126 INFO 34173 --- [ Thread-3] c.l.g.r.ApplicationFeatureManager : ------------------- grantable features authority --------------
FEATURE://CONSOLE/MENU/BUSI/BUSI-REGISTER
FEATURE://CONSOLE/MENU/FILE-SERVICE-MNGMT/FILE-ACCESS-AUTHORIZE
FEATURE://CONSOLE/MENU/FILE-SERVICE-MNGMT/REGISTER-FILE-SERVICE
FEATURE://CONSOLE/MENU/LOGS-MNGMT/OPERATION-LOGS
FEATURE://CONSOLE/MENU/ORG-MANAGEMENT/ORG-AUTHORIZE
FEATURE://CONSOLE/MENU/ORG-MANAGEMENT/ORG-MEMBER-AUTHORIZE
FEATURE://CONSOLE/MENU/ORG-MANAGEMENT/ORG-MEMBER-REGISTER
FEATURE://CONSOLE/MENU/ORG-MANAGEMENT/ORG-REGISTER
FEATURE://CONSOLE/MENU/ORG-MANAGEMENT/ORG-SETTINGS
FEATURE://CONSOLE/MENU/SECURITY/SECURITY-ACCOUNT
FEATURE://CONSOLE/MENU/USER-MNGMT/LATEST-REG-USERS
FEATURE://CONSOLE/MENU/USER-MNGMT/USER-OPEN-REG-AUTHORIZE
FEATURE://CONSOLE/MENU/USER-MNGMT/USER-OPERATION-AUTHORIZE
FEATURE://PLATFORM/TOOLBAR/TBAR-ACCOUNT-PROFILE
FEATURE://PLATFORM/TOOLBAR/TBAR-LOGOUT
Properties of [com.linkgie.galaxyplatform.security.core.repo.mongodb.AccountPO] : 23
2024-03-21 19:28:27.481 INFO 34173 --- [ Thread-3] c.l.g.s.s.AccountService :
-------------------- The generated random password of root user[root] --------------------
FubQ1M1L6Ra
---------------------------------------------------------------------------------
2024-03-21 19:28:30.085 INFO 34173 --- [ Thread-3] o.s.b.w.e.t.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2024-03-21 19:28:30.442 INFO 34173 --- [ Thread-3] o.s.b.SpringApplication : Started application in 9.16 seconds (JVM running for 10.88)
[200]启动成功!
在输出的日志中,由于在应用配置文件没有设置 root 用户的默认密码,所以首次启动会自动生成一个随机的密码,以日志形式输出如下:
2024-03-21 19:28:27.481 INFO 34173 --- [ Thread-3] c.l.g.s.s.AccountService :
-------------------- The generated random password of root user[root] --------------------
FubQ1M1L6Ra
---------------------------------------------------------------------------------
关于 GAPP 应用的详细配置,请参考:GAPP 应用配置
root 首次登录
浏览器中打开 http://localhost:8080 打开应用页面
当前应用只有一个根账号 root ,输入用户名 root 和随机密码,登录后默认进入应用的控制台。
添加子模块
<未完待续>