หน้านี้ยังไม่พร้อมใช้งานในภาษาท้องถิ่นของคุณ เรากำลังพยายามอย่างหนักเพื่อเพิ่มเวอร์ชันภาษาอื่น ๆ เพิ่มเติม ขอบคุณสำหรับการสนับสนุนเสมอมา

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Help Center/ CodeArts Build/ FAQs/ Maven Builds/ How Do I Use jib-maven-plugin to Build a Maven Project and Create an Image?

How Do I Use jib-maven-plugin to Build a Maven Project and Create an Image?

Updated on 2024-10-10 GMT+08:00

Symptoms

The Maven image provided by CodeArts does not contain the Docker environment. An error is reported when an image is created using CodeArts Build and the docker-maven-plugin extension. For example:

INFO: I/O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: No such file or directory

This document describes how to use the jib-maven-plugin extension to create a TAR file with an image in a Maven environment without Docker.

Solution

  1. Modify the code of the project for which you want to create an image.

    Find the POM file and import the extension. The content is as follows:

    <!--Use the jib extension.-->
                <plugin>
                    <groupId>com.google.cloud.tools</groupId>
                    <artifactId>jib-maven-plugin</artifactId>
                    <version>1.3.0</version>
                    <configuration>
                        <!--The from node is used to set the base image, which is equivalent to the FROM keyword in a Dockerfile.-->
                        <from>
                            <!—You are advised to use SWR public images for fast download and more stable download. -->
                            <image>swr.example.myxxcloud.com/xxxx/xxx:xxxxx</image>
                        </from>
                        <to>
                            <!--Image name and tag. The mvn built-in variable ${project.version} is used, indicating the version of the current project.-->
                            <image> hellojib:${project.version}</image>
                        </to>
                        <!--Attribute related to containers-->
                        <container>
                            <!--JVM memory parameter-->
                            <jvmFlags>
                                <jvmFlag>-Xms4g</jvmFlag>
                                <jvmFlag>-Xmx4g</jvmFlag>
                            </jvmFlags>
                            <!--Port to be exposed-->
                            <ports>
                                <port>8080</port>
                            </ports>
                        </container>
                    </configuration>
                </plugin>
    • From tag: Set the base image, which is equivalent to the FROM keyword in a Dockerfile. You are advised to use the image in SWR because the download speed is fast and stable.
    • To tag: Set the name and tag of the created image.
    • Container tag: Set the container attribute, JVM memory parameter, port, and so on.
    • mainClass tag: Set the main program for starting the project, that is, the Application class of Spring Boot.
  2. Create build task and execute it.
    1. Add two build actions: Build with Maven and Upload to Release Repos. Change the default Maven build command to the following command:
      mvn compile jib:buildTar -Dmaven.test.skip=true -U -e -X –B
      NOTE:

      The Jib build tool provides four powerful functions. The build and dockerBuild commands cannot be used to create images because the build tool is built without the Docker environment. You can only run the buildTar command to create a .tar file that contains images.

      • build allows you to create images and push them to a remote repository.
      • buildTar provides the function of creating a .tar file that contains images.
      • dockerBuild provides the function of creating Docker images to a local PC.
      • exportDockerContext provides the Dockerfile creation function.

      After the building is successful, the following information is displayed in the log:

    2. In the target directory of the Java project, the jib-image.tar file is generated. In addition, the task uploads the software to release repos.
  3. Use the tar image.

    Run the script or download command to download the .tar file from the release repo o the server where the application is to be deployed. Run the docker load command to load the image of the .tar file to the local image repository, and run the docker run command to start the image.

เราใช้คุกกี้เพื่อปรับปรุงไซต์และประสบการณ์การใช้ของคุณ การเรียกดูเว็บไซต์ของเราต่อแสดงว่าคุณยอมรับนโยบายคุกกี้ของเรา เรียนรู้เพิ่มเติม

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback