推荐 IntelliJ IDEA 社区版(开源免费)
https://github.com/JetBrains/intellij-community
1.8+
如果你已经 fork
了 Halo
,请将以下命令中的 halo-dev
替换为你的 Github 用户名
。
git clone https://github.com/halo-dev/halo
// 如果你在 Github 上已经添加了你的 ssh key,请使用以下命令进行 clone:
git clone git@github.com:halo-dev/halo.git
git submodule init
git submodule update
导入项目的时候请选择 Gradle 项目
进行导入。
IntelliJ IDEA
在导入项目的时候请勾选auto import
,推荐使用gradle wrapper
。
Halo
运行方式总体来讲有以下两种:
Application
主类(配合 IDE 运行)如果需要指定配置,请在 Run/Debug Configuration
内进行设置 VM options
(这里推荐采用上文的自定义配置),例如:
-Dspring.profiles.active=dev
-Dhalo.auth-enabled=false
-Dhalo.production-env=false
gradle bootRun task
运行(不需要 IDE)在项目根目录下运行以下命令:
# 类 Unix 用户
./gradlew bootRun
# Windows 用户
./gradlew.bat bootRun
如果需要手动指定配置,可添加 --args
参数(这里推荐采用上文的自定义配置),例如:
# 类 Unix 用户
./gradlew bootRun --args="--spring.profiles.active=dev --server.port=2333"
# Windows 用户
./gradlew.bat bootRun --args="--spring.profiles.active=dev --server.port=2333"
如果一切正常且没有额外指定配置,则可根据控制台的输出链接进行访问 Halo
:
2019-06-06 16:20:52.285 INFO 1330 --- [ restartedMain] run.halo.app.listener.StartedListener : Halo started at http://127.0.0.1:8090
2019-06-06 16:20:52.285 INFO 1330 --- [ restartedMain] run.halo.app.listener.StartedListener : Halo admin started at http://127.0.0.1:8090/admin
2019-06-06 16:20:52.285 DEBUG 1330 --- [ restartedMain] run.halo.app.listener.StartedListener : Halo doc was enable at http://127.0.0.1:8090/swagger-ui.html # 仅在开发环境才会输出
运行命令中添加 VM options
,例如:
-Dspring.profiles.active=dev
运行命令中添加参数,例如:
--spring.profiles.active=dev
在开发环境下,修改代码之后,每次都需要重启应用,是一个非常耗时的操作。
有一个专门解决这个问题的工具,那就是 JRebel,但是它的费用实在是太昂贵,作为普通的开发者很难承受这笔费用(但不推荐使用破解版)。
于是 Halo
最后采用了 Spring Boot
官方推荐的 Developer Tools。
这里以 IntelliJ IDEA
为例。
Settings
(Preferences on macOS)。Build, Execution, Deployment > Compiler
. 启用 Build project automatically
。应用
。Ctrl+Shift+A
(Cmd+Shift+A on macOS)快捷键,然后搜索 Registry
。打开之后找到 compiler.automake.allow.when.app.running
,并启用它 (IntelliJ IDEA 15 and newer)。