日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

編譯部署代碼包

您可以在本地Java運行環境(Maven或Serverless Devs工具)編譯程序,打包為ZIP包或JAR包,然后在函數計算控制臺或使用Serverless Devs工具上傳代碼包,并正確運行您的代碼。

Java運行時依賴庫

要創建部署代碼包,請將函數代碼和依賴庫共同編譯并打包為ZIP包或JAR包。

函數計算平臺為Java運行時提供以下依賴庫:

以上依賴庫可通過Maven中央存儲庫獲取。獲取以上依賴庫后將其添加到您的pom.xml文件中,如下所示:

<!-- https://mvnrepository.com/artifact/com.aliyun.fc.runtime/fc-java-core -->
<dependency>
    <groupId>com.aliyun.fc.runtime</groupId>
    <artifactId>fc-java-core</artifactId>
    <version>1.4.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.aliyun.fc.runtime/fc-java-event -->
<dependency>
    <groupId>com.aliyun.fc.runtime</groupId>
    <artifactId>fc-java-event</artifactId>
    <version>1.2.0</version>
</dependency>
說明

如果依賴包太大,可將依賴打包到層中,以減少代碼包體積。具體操作,請參見創建自定義層

使用Maven編譯并部署

前提條件

安裝Java和Maven。關于Java的詳細信息,請參見官網。關于Maven的詳細信息,請參見Installing Apache Maven

操作步驟

  1. 創建一個Java項目,其中App.java文件路徑如下。

    src/main/java/example/App.java  

    App.java文件中輸入示例代碼。具體示例代碼,請參見請求處理程序(Handler)上下文

    package example;
    
    import com.aliyun.fc.runtime.Context;
    import com.aliyun.fc.runtime.StreamRequestHandler;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    
    public class App implements StreamRequestHandler {
    
        @Override
        public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
            outputStream.write(new String("hello world").getBytes());
        }
    }
  2. pom.xml文件中配置build,示例如下。

    <build>
            <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-shade-plugin</artifactId>
                      <version>3.2.1</version>
                      <executions>
                        <execution>
                          <phase>package</phase>
                          <goals>
                            <goal>shade</goal>
                          </goals>
                          <configuration>
                            <filters>
                              <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                  <exclude>META-INF/*.SF</exclude>
                                  <exclude>META-INF/*.DSA</exclude>
                                  <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                              </filter>
                            </filters>
                          </configuration>
                        </execution>
                      </executions>
                  </plugin>
            </plugins>
    </build>
    說明

    您可以使用Apache Maven Shade插件或Apache Maven Assembly插件,以上示例僅以Apache Maven Shade插件為例。

    展開查看完整的pom.xml文件示例。

    <project xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>example</groupId>
      <artifactId>HelloFCJava</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>HelloFCJava</name>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>com.aliyun.fc.runtime</groupId>
          <artifactId>fc-java-core</artifactId>
          <version>1.4.1</version>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>3.2.1</version>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>shade</goal>
                  </goals>
                  <configuration>
                    <filters>
                      <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                          <exclude>META-INF/*.SF</exclude>
                          <exclude>META-INF/*.DSA</exclude>
                          <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                      </filter>
                    </filters>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
      </build>
    
      <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.test.skip>true</maven.test.skip>
      </properties>
    </project>
  3. 打開命令行窗口,切換至項目的根目錄,然后執行mvn clean package命令打包。

    示例代碼如下。

    [INFO] Scanning for projects...
     ...  ....   ....
    [INFO] --------------------------< example:example >---------------------------
    [INFO] Building java-example 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
     ...  ....   ....
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  11.681 s
    [INFO] Finished at: 2020-03-26T15:55:05+08:00
    [INFO] ------------------------------------------------------------------------
    • 如果顯示編譯失敗,請根據輸出的編譯錯誤信息調整代碼。

    • 如果編譯成功,編譯后的JAR包位于項目文件夾內的target目錄內,并根據pom.xml內的artifactIdversion字段命名為HelloFCJava-1.0-SNAPSHOT.jar

      重要

      針對macOS和Linux操作系統,壓縮前請確保代碼文件具有可讀和可執行權限。

  4. 登錄函數計算控制臺,上傳代碼包。

    image

  5. 函數詳情配置頁簽,確認請求處理程序正確性,您的請求處理程序需配置為[包名].[類名]::[方法名]。例如,您的包名為example,類名為App,方法名為handleRequest,則請求處理程序可配置為example.App::handleRequest,如果不正確點擊編輯進行修改。

    image

  6. 代碼頁簽,單擊測試函數進行測試。

    image

使用Serverless Devs編譯并部署

前提條件

操作步驟

  1. 執行以下命令,初始化項目。

    s init 

    根據界面提示依次選擇阿里云廠商、模板、運行時以及部署應用的地域和函數名稱等。

    image

  2. 執行以下命令,進入項目目錄。

    cd start-fc-event-java8

    代碼目錄結構如下:

    start-fc-event-java8
    ├── src
    │   └── main
    │       └── java
    │           └── example
    │               └── App.java
    ├── pom.xml
    ├── readme
    └── s.yaml
  3. 執行以下命令,部署項目。

    s deploy

    執行該命令會先執行pre-deploypre-deploy會執行mvn package編譯打包,然后上傳部署代碼包。輸出示例如下:

    [2022-04-07 12:00:09] [INFO] [S-CORE] - Start the pre-action
    [2022-04-07 12:00:09] [INFO] [S-CORE] - Action: mvn package
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------< example:HelloFCJava >-------------------------
    [INFO] Building HelloFCJava 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    ......
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  3.617 s
    [INFO] Finished at: 2022-04-07T20:00:14+08:00
    [INFO] ------------------------------------------------------------------------
    [2022-04-07 12:00:14] [INFO] [S-CORE] - End the pre-action
    
    ? Checking Service, Function (0.64s)
    ? Creating Service, Function (0.71s)
    
    Tips for next step
    ======================
    * Display information of the deployed resource: s info
    * Display metrics: s metrics
    * Display logs: s logs
    * Invoke remote function: s invoke
    * Remove Service: s remove service
    * Remove Function: s remove function
    * Remove Trigger: s remove trigger
    * Remove CustomDomain: s remove domain
    
    
    
    helloworld:
      region:   cn-hangzhou
      service:
        name: hello-world-service
      function:
        name:       start-fc-event-java8
        runtime:    java8
        handler:    example.App::handleRequest
        memorySize: 128
        timeout:    60
  4. 執行s invoke命令進行測試。

    輸出示例如下:

    ?  start-fc-event-java8 s invoke
    ========= FC invoke Logs begin =========
    FC Initialize Start RequestId: b246c3bf-06bc-49e5-92b8-xxxxxxxx
    FC Initialize End RequestId: b246c3bf-06bc-49e5-92b8-xxxxxxxx
    FC Invoke Start RequestId: b246c3bf-06bc-49e5-92b8-xxxxxxxx
    FC Invoke End RequestId: b246c3bf-06bc-49e5-92b8-xxxxxxxx
    
    Duration: 7.27 ms, Billed Duration: 8 ms, Memory Size: 128 MB, Max Memory Used: 65.75 MB
    ========= FC invoke Logs end =========
    
    FC Invoke Result:
    hello world
    
    
    
    End of method: invoke