跳至主要内容

Getting Started

在 ChatGPT 中打开

本文概述了使用 webforJ 原型 创建新的 webforJ 应用程序的步骤。原型提供了预先配置的项目结构和起始代码,让您能够快速启动项目并投入运行。 要从原型创建新的 webforJ 应用程序,可以使用 startforJ命令行

前提条件

在开始之前,请查看设置和使用 webforJ 的必要 前提条件

使用 startforJ

创建新的 webforJ 应用程序最简单的方法是 startforJ,它基于所选的 webforJ 原型生成一个最小化的起始项目。这个起始项目包括所有必需的依赖项、配置文件和预制布局,让您能够立刻开始构建。

使用 startforJ 进行自定义

当您使用 startforJ 创建应用程序时,您可以通过提供以下信息进行自定义:

  • 基本项目元数据(应用名称、组 ID、工件 ID)
  • webforJ 版本和 Java 版本
  • 主题颜色和图标
  • 原型
  • 风味

有两种风味选项可供选择,其中“webforJ Only”是默认选项:

  • webforJ Only:标准 webforJ 应用
  • webforJ + Spring Boot:支持 Spring Boot 的 webforJ 应用
可用原型

webforJ 提供了几个预定义的原型,可以帮助您快速入门。有关可用原型的完整列表,请参阅 原型目录

使用这些信息,startforJ 将根据您选择的原型及自定义选项创建基本项目。 您可以选择将项目下载为 ZIP 文件或直接发布到 GitHub。

下载项目后,请在 IDE 中打开项目文件夹并继续 运行应用程序

使用命令行

如果您更喜欢使用命令行,您可以使用 Maven 原型直接生成项目:

要创建和搭建一个新的 hello-world 项目,请按照以下步骤进行:

  1. 导航到正确的目录: 打开终端并移动到您想创建新项目的文件夹。
  2. 运行 archetype:generate 命令: 使用下面的Maven命令,并根据您的项目需求自定义groupId、artifactId和版本。
mvn -B archetype:generate \
-DarchetypeGroupId=com.webforj \
-DarchetypeArtifactId=webforj-archetype-hello-world \
-DarchetypeVersion=LATEST \
-DgroupId=org.example \
-DartifactId=my-app \
-Dversion=1.0-SNAPSHOT \
-Dflavor=webforj \
-DappName=MyApp
参数解释
archetypeGroupId该原型的组ID为com.webforj。
archetypeArtifactId指定要使用的原型名称。
archetypeVersion指定要使用的原型版本。这确保生成的项目与特定的原型版本兼容。使用 LATEST 选择最新可用版本。
groupId表示生成项目的命名空间。通常结构类似于Java包,例如org.example,用于唯一识别您的组织或项目域。
artifactId指定生成项目的名称。它将是生成的工件和项目文件夹的名称。
version定义生成项目的版本。常见约定为 MAJOR.MINOR-SNAPSHOT,例如 1.0-SNAPSHOT,其中 SNAPSHOT 表示项目仍在开发中。
flavor选择项目风味:
  • webforj - 标准 webforJ 应用。
  • webforj-spring - webforJ 应用,支持 Spring Boot(需要 webforJ 25.02 或更高版本)。
appName项目 POM 文件中可选的参数。根据使用的 webforJ 原型,它可以作为应用程序的默认标题。

运行命令后,Maven将生成运行项目所需的项目文件。

Running the app

Before running your app, install the prerequisites if you haven't yet. Then, navigate to the project's root directory and run the following command:

mvn
Full maven command

The shorthand mvn command works because the archetype's POM file includes a <defaultGoal> configuration that automatically runs the appropriate goal for your project type. If your project doesn't have <defaultGoal>, run the following:

# for a standard webforJ app
mvn jetty:run
# for a webforJ + Spring Boot app
mvn spring-boot:run

Once the server is running, open your browser and go to http://localhost:8080 to view the app.