如何解決 CloudFormation 中的「java.lang.ClassNotFoundException:com.example.package.resource.HandlerWrapper」錯誤?
1 分的閱讀內容
0
嘗試在 AWS CloudFormation 中叫用資源供應商時,我收到下列錯誤:「java.lang.ClassNotFoundException:com.example.package.resource.HandlerWrapper」
簡短說明
開發或測試「資源供應商結構描述」檔案時,您會收到「java.lang.ClassNotFoundException:com.example.package.resource.HandlerWrapper」錯誤。您呼叫 cfn test 或 sam local invoke,但專案中的 /target/ 目錄不包含有效的 .jar 檔案。
如需其他與使用資源供應商相關的錯誤,請參閱下文:
- 如何解決在 CloudFormation 中使用 CloudFormation CLI 執行 cfn generate 命令時出現的「資源規格無效」錯誤?
- 如何解決 CloudFormation 中的「模型驗證失敗 (#:不允許無關的金鑰 [Key])」錯誤?
- 如何解決在 CloudFormation 中使用資源供應商類型建立資源時出現的「資源等待實體資源建立時發生逾時」錯誤?
- 如何解決當我在 CloudFormation 中的資源供應商資源使用 Fn::GetAtt 函數時發生的「屬性 'Key' 不存在」錯誤?
解決方案
依預設,.jar 檔案的名稱為 organization-service-resource-handler-1.0-SNAPSHOT.jar 格式,並且在專案根目錄的 pom.xml 檔案中進行設定。例如:
<groupId>com.organization.service.resource</groupId> <artifactId>organization-service-resource-handler</artifactId> <name>organization-service-resource-handler</name> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging>
若要建置專案,請執行 cfn generate。然後,執行 mvn package。例如:
$ cfn generate Generated files for Organization::Service::Resource $ mvn package [INFO] Scanning for projects... [INFO] [INFO] --< software.organization.service.resource:organization-service-resource-handler >-- [INFO] Building organization-service-resource-handler 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 21.690 s [INFO] Finished at: 2020-07-14T16:02:47-05:00 [INFO] ------------------------------------------------------------------------
**注意事項:**如果建置和測試成功,則 mvn 會在 /target/ 目錄中建立必要的 .jar 檔案。
若要略過對未完成的單元測試的測試,請執行 mvn -Dmaven.test.skip=true package,而不要執行 mvn package。
$ cfn generate Generated files for Organization::Service::Resource $ mvn package -Dmaven.test.skip=true package [INFO] Scanning for projects... [INFO] [INFO] --< software.organization.service.resource:organization-service-resource-handler >-- [INFO] Building organization-service-resource-handler 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 21.690 s [INFO] Finished at: 2020-07-14T16:02:47-05:00 [INFO] ------------------------------------------------------------------------
**提示:**您可以從專案根目錄導覽至目錄 /target/surefire-reports 來疑難排解測試。
相關資訊
AWS CloudFormation CLI (來自 GitHub 網站)
AWS 官方已更新 2 年前
沒有評論
相關內容
- AWS 官方已更新 2 年前
- AWS 官方已更新 4 年前
- AWS 官方已更新 2 年前