IntelliJ IDEA 2021.2 Help

Work with artifacts处理工件

See also, Project Structure / Artifacts.另请参见项目结构/工件

What is an artifact?什么是工件?

An artifact is an assembly of your project assets that you put together to test, deploy or distribute your software solution or its part. 工件是您的项目资产的集合,您将其放在一起以测试、部署或分发您的软件解决方案或其部分。Examples are a collection of compiled Java classes or a Java application packaged in a Java archive, a Web application as a directory structure or a Web application archive, etc.示例包括编译的Java类集合或打包在Java存档中的Java应用程序、作为目录结构的Web应用程序或Web应用程序存档等。

An artifact can be an archive file or a directory structure that includes the following structural elements:工件可以是包含以下结构元素的归档文件或目录结构:

  • Compilation output for one or more of your modules一个或多个模块的编译输出

  • Libraries included in module dependencies模块依赖项中包含的库

  • Collections of resources (web pages, images, descriptor files, etc.)资源集合(网页、图像、描述符文件等)

  • Other artifacts

  • Individual files, directories and archives.单个文件、目录和档案。

Work with artifact configurations使用工件配置

Artifacts are generated according to artifact configurations. 根据工件配置生成工件。The artifact configurations are managed in the Project Structure dialog (File | Project Structure | Artifacts).工件配置在项目结构对话框(“文件”|“项目结构”|“工件”)中管理。

The key part of configuring an artifact is specifying the artifact structure and contents on the Output Layout tab.配置工件的关键部分是在“输出布局”选项卡上指定工件结构和内容。

Build artifacts构建工件

You can initiate building an artifact yourself: Build | Build Artifacts.您可以自己开始构建工件:“构建”|“构建工件”。

You can as well build an artifact by executing a run/debug configuration:您还可以通过执行运行/调试配置来构建工件:

In the corresponding run/debug configuration, add the Build <ArtifactName> artifact task to the Before launch task list. The artifact will be built automatically when you execute the run/debug configuration (Run | Run or Run | Debug).在相应的运行/调试配置中,添加“构建<工件名称>工件”任务添加到“启动前”任务列表。当您执行运行/调试配置(“运行|运行”或“运行|调试”)时,将自动构建工件。

Including the Build artifact task in a run/debug configuration makes sense when the run/debug configuration somehow uses the corresponding artifact, e.g. starts the application packaged in a JAR artifact or deploys a WAR or EAR artifact to an application server.当运行/调试配置以某种方式使用相应的工件时,将“构建工件”任务包括在运行/调试配置中是有意义的,例如启动打包在JAR工件中的应用程序,或者将WAR或EAR工件部署到应用程序服务器。

By default, an artifact, when built, is placed into the out/artifacts/<artifact_dir> folder.默认情况下,工件在构建时放置在“out/artifacts/<artifact_dir>”文件夹

Build options (Build, Rebuild, etc.)构建选项(构建、重建等)

When building an artifact (Build | Build Artifacts), you have the following options:构建工件(“构建”|“构建工件”)时,您有以下选项:

  • Build.构建。 When used for the first time, the whole artifact is built. 当第一次使用时,整个工件被构建。Each next time you use this option, only the part of the artifact affected by the changes you have made since the last build is built and added to the output folder.每次下次使用此选项时,只会生成受自上次生成以来所做更改影响的工件部分,并将其添加到输出文件夹中。

  • Rebuild.重新构建。 Build the whole artifact as if for the first time. 第一次构建整个工件。Technically, this is Clean followed by Build.从技术上讲,这是清空,然后是构建

  • Clean.清空。 Delete all the contents of the artifact output directory.删除工件输出目录的所有内容。

  • Edit.编辑。 Edit the artifact configuration.编辑工件配置

Run JAR artifacts运行JAR工件

To run Java applications packaged in Java archives (JARs), IntelliJ IDEA provides the JAR Application run configurations. 为了运行Java归档(JAR)中打包的Java应用程序,IntelliJ IDEA提供了JAR应用程序运行配置。To create such a run configuration:要创建这样的运行配置,请执行以下操作:

  1. Open the Run/Debug Configurations dialog (e.g. Run | Edit Configurations).打开运行/调试配置对话框(例如“运行”|“编辑配置”)。

  2. Click Icons general add and select JAR Application.单击Icons general add并选择JAR应用程序

Deploy artifacts to application servers and cloud platforms将构件部署到应用服务器和云平台

Many of the artifact formats (for example, WAR, Exploded WAR, EAR, Exploded EAR) are suitable for deployment to application servers and cloud platforms. 许多工件格式(例如,WAR、分解WAR、EAR、分解EAR)都适合部署到应用服务器和云平台。Here is how you deploy such artifacts:以下是您如何部署此类构件:

  1. In a server or cloud run/debug configuration, specify the artifact to be deployed. 在服务器或云运行/调试配置中,指定要部署的工件。(Use the Deployment tab or field.)(使用“部署”选项卡或字段。)

  2. Execute the run/debug configuration or use the Deploy command (Deployment console deploy all) in the Application Servers, Run or Debug tool window.在“应用程序服务器”、“运行”或“调试”工具窗口中执行运行/调试配置或使用部署命令(Deployment console deploy all)。

Examples例子

Examples of the procedures discussed on this page can be found in the following tutorials:本页讨论的步骤示例可在以下教程中找到:

Last modified: 08 March 2021