源码编译geoserver(idea)

官方教程:https://docs.geoserver.org/main/en/developer/quickstart/intellij.html

 

从 git 存储库中检出源代码:

git clone https://github.com/geoserver/geoserver.git geoserver

列出可用的分支:

% git branch
   2.21.x
   2.22.x
 * main

选择main最新动态:

% git checkout main

或者为不太可能经常更改的版本选择一个稳定的分支:

% git checkout 2.22.x

在这个例子中,我们假设您的源代码位于名为的目录中geoserver,但通常建议使用更具描述性的名称。

将模块导入 IntelliJ 

  1. 运行 IntelliJ IDE

  2. 从初始面板中选择Open

    ../_images/intellij_open.png
  3. 导航到geoserver/src/pom.xml目录并单击OK

    ../_images/intellij_import.png
  4. 当系统询问时单击Open as a Project

    ../_images/intellij_project.png
  5. 或者,根据平台不同,IntelliJ 可能会要求Trust the Project

    ../_images/intellij_project_trust.png
  6. 等待 IntelliJSync依赖项,可以从Build底部的选项卡面板跟踪该过程。

    复制代码

完成 GeoServer 项目配置

  1. 点击File > Project Structure

    ../_images/intellij_project_struct.png
  2. 更新并根据 GeoServer 版本Name选择正确的。SDK

    ../_images/intellij_project_sdk.png
  3. 点击File > Settings

    ../_images/intellij_project_settings.png
  4. ,启用Build, Execution, Deployment > Compiler > Annotation ProcessorsAnnotation processing

    ../_images/intellij_project_settings_annotation_processing.png
  5. 点击Build > Rebuild Project

    ../_images/intellij_project_rebuild.png

从 IntelliJ 运行 GeoServer 

  1. 从项目浏览器中选择web-app模块

  2. 导航到org.geoserver.web

  3. 右键单击Start该类,然后单击Modify Run Configuration...

    查看 ../_images/intellij_run.png
    1.   这里如果找不到"modify run config..",就在最上方工具栏点run-->edit config..
  4. 正确设置非常重要打开对话框后,微调启动环境(包括设置。设置满意后,单击Working directorysrc/web/appEdit ConfigurationsGEOSERVER_DATA_DIRjetty.portOK

    ../_images/intellij_run_config.png
  5. 现在可以通过选择运行 GeoServerRun -> Run 'Start'

    ../_images/intellij_run_start.png

故障排除

  1. 如果出现“无法找到符号类 ASTAxisId”等错误,则表示某些生成的代码未包含在构建中。使用wcs1_1作为工作目录,运行 mvn clean install

  2. 如果出现类似 的编译器错误java.lang.NoSuchMethodError,则可能是由于 Error Prone。此工具默认关闭,但有时在导入 IntelliJ 后会打开。有两种方法可以修复它:
    1. 进入 Maven 工具窗口并取消选中errorprone配置文件,然后单击Reimport All Maven Projects

      ../_images/intellij_maven_errorprone.png
    2. 要使用errorprone,特别是执行 QA 检查,请安装Error Prone Compiler插件,重新启动 IDE 并将Javac with error-prone设置为项目的默认编译器。请注意,这会减慢构建速度。

  3. 如果出现“找不到符号 AbstractUserGroupServiceTest”等错误,请security-tests在安全模块中重建项目。右键单击security-tests项目,然后单击重建。

  4. 在 IntelliJ 的最新版本中,注释处理器已启用。如果因此出现错误,请从编译器设置中取消选中此选项。

    ../_images/intellij_project_settings_annotation_processing.png
  5. 如果 IntelliJ 出现类似以下错误消息,请点击Command line is too long.Shorten the command line and run.

    ../_images/intellij_run_start_error.png

如果有服务器在 localhost:8080 上运行,请查看Eclipse 指南以获取有关更改为其他端口的说明。

使用扩展运行 GeoServer 

上述说明假设运行 GeoServer 时未启用任何扩展。如果需要某些扩展,模块web-app会声明一些配置文件,这些配置文件将在运行时启用特定扩展Start。要启用扩展,请打开工具并选择要启用的配置文件。Maven Projects

../_images/intellij_run_profile.png

可以在 中找到受支持的配置文件的完整列表src/web/app/pom.xml

为了将 GeoServer 执行与新模块同步,请从工具中单击按钮 (1),然后单击(2),完成后单击(3)。Maven ProjectsReload All Maven ProjectBuild the ProjectRun 'Start'

../_images/intellij_run_profile_sync.png

访问 GeoServer 首页

开发环境

代码格式化

GeoServer 使用 [palantir-java-format]( https://github.com/palantir/palantir-java-format?tab=readme-ov-file#palantir-java-format ),它是 google-java-format AOSP 样式更新的 Lamda 表达式和 120 列的一个分支。

格式化插件嵌入在构建中,并将在每次构建时重新格式化代码,以匹配编码约定。提交之前,请务必在本地构建!

palantir-java-format项目为 IntelliJ提供了一个[插件]( https://plugins.jetbrains.com/plugin/13180-palantir-java-format )。

posted @ 2024-12-25 14:29  南水之源  阅读(389)  评论(0)    收藏  举报