本地部署 Google Cloud 函数失败,显示 “javap -cp: 找不到类”。

huangapple go评论68阅读模式
英文:

Local deploy of Google cloud function fails with "javap -cp: Class not found"

问题

使用STS时,我的云函数在本地使用以下命令正常运行:

mvn function:run -Drun.functionTarget=functions.Gcpfunc

然而,当进行本地源代码或预打包的 Lite JAR 部署时,GCP 上的构建日志显示在以下阶段出现错误:

"builder":运行 "javap -classpath sts2gcphttpfunc-0.0.1-SNAPSHOT.jar functions.Gcpfunc"
"builder":错误:找不到类:functions.Gcpfunc。

然而,如果我直接在 GCP 上创建一个函数并部署相同的代码,上述行在日志中显示为成功。

我的系统规格:Java 8,Maven 3.6.3,Windows 8.1
附件:pom.xml 的截图,"Source" 部署和 "JAR" 部署的构建日志错误截图

源代码部署命令:

gcloud functions deploy Gcpfunction3 --region=us-east1 --entry-point=functions.Gcpfunc --runtime=java11 --trigger-http --allow-unauthenticated

Lite JAR 部署命令:

gcloud functions deploy Gcpfunction3 --region=us-east1 --entry-point=functions.Gcpfunc --runtime=java11 --trigger-http --source=target/deployment --allow-unauthenticated

POM.xml 图片
本地部署 Google Cloud 函数失败,显示 “javap -cp: 找不到类”。
本地部署 Google Cloud 函数失败,显示 “javap -cp: 找不到类”。

英文:

Using STS my cloud function works fine locally using the below command:

mvn function:run -Drun.functionTarget=functions.Gcpfunc

However, when doing a local Source or pre-packaged Lite JAR deployment, the build logs on GCP show error at the below stage:

"builder": Running "javap -classpath sts2gcphttpfunc-0.0.1-SNAPSHOT.jar functions.Gcpfunc" 
"builder": Error: class not found: functions.Gcpfunc. 

However, if I create a function directly on GCP and deploy the same, the above line shows success in the logs.

My System specs: Java 8, Maven 3.6.3, Windows 8.1
Attachments: Screenshots of pom.xml, build log error of "Source" and "JAR" deployment

Command for source deploy:

gcloud functions deploy Gcpfunction3 --region=us-east1 --entry-point=functions.Gcpfunc --runtime=java11 --trigger-http --allow-unauthenticated

Command for Lite JAR deployment:

gcloud functions deploy Gcpfunction3 --region=us-east1 --entry-point=functions.Gcpfunc --runtime=java11 --trigger-http --source=target/deployment --allow-unauthenticated

POM.xml Image
本地部署 Google Cloud 函数失败,显示 “javap -cp: 找不到类”。
本地部署 Google Cloud 函数失败,显示 “javap -cp: 找不到类”。

答案1

得分: 0

从Google文档语法的本地测试示例中,可以看出:

mvn function:run -Drun.functionTarget=your.package.yourFunction

但在文档中的gcloud部署命令示例中,语法为:

gcloud functions deploy NAME --entry-point NAME --runtime RUNTIME TRIGGER [FLAGS...]

请注意,在gcloud命令中的--entry-point应该包含类名,而在mvn function:run命令中则应该包含包名。我认为这是主要问题,因此请验证这个值。关于如何使用它的详细信息,您可以在这里找到。

还有一点,可能不太确定是否重要,就是您在Maven中使用的是Java 8,而在Google Cloud Functions中只能使用Java 11,实际上在gcloud命令中您正在使用Java 11。

英文:

When you take a look in the example from google documentation syntax of local test is:

mvn function:run -Drun.functionTarget=your.package.yourFunction

But in the gcloud deploy command example from documentation sytax is:

gcloud functions deploy NAME --entry-point NAME --runtime RUNTIME TRIGGER [FLAGS...]

So please notice that --entry-point in gcloud command is should contain class name while in mvn function:run command it's with package. I think this is main problem, so verify this value. Exact infomation how to use it you may find here.

One more, honestly not sure if important, is that you are using java 8 in maven, while in GCF you can use only java 11, and actually you are using it in the gcloud command.

答案2

得分: 0

这个问题已经解决。必须从 pom.xml 中移除 Spring-boot-maven-plugin,这样类文件就不会被创建在 Boot-inf 文件夹中。

英文:

This has been resolved. Had to remove Spring-boot-maven-plugin from pom.xml so that Class files are not created in Boot-inf folder

huangapple
  • 本文由 发表于 2020年10月24日 15:44:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/64511140.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定