java在Google Cloud Shell中运行示例Google Maven项目
我是全新的GCP世界。我正在尝试运行Google的Github-repo on Cloud Shell中的一个pubsub示例(https://github.com/googleapis/java-pubsub/blob/HEAD/samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.java)
他们的文档还有到Cloud Shell(https://github.com/googleapis/java-pubsub/tree/ff9c9c15a9efb10d5cbc9328c7a703a20b5d4b44#samples)的链接
我可以通过运行mvn clean install
在云shell上构建。但是当我运行Java类时,我看到了一个例子。java(在填写项目id和子选项id之后),我得到以下错误
satish_anupindi84@cloudshell:~$ cd '/home/satish_anupindi84' && env '/usr/lib/jvm/java-11-openjdk-amd64/bin/java' '-Dfile.encoding=UTF-8' '-cp' '/home/satish_anupindi84/.theia/workspace-storage/e742f48ad7fde7236560e8cf9e48d278/redhat.java/jdt_ws/jdt.ls-java-project/bin' 'pubsub.SubscribeWithAvroSchemaExample' Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at pubsub.SubscribeWithAvroSchemaExample.main(SubscribeWithAvroSchemaExample.java:39)
有人能试试这个,让我知道他们得到了什么吗
手动运行,没有任何进展
satish_anupindi84@cloudshell:~/cloudshell_open/java-pubsub-2$ cd samples/snippets/ satish_anupindi84@cloudshell:~/cloudshell_open/java-pubsub-2/samples/snippets$ env '/usr/lib/jvm/java-11-openjdk-amd64/bin/java' '-Dfile-encoding=UTF-8' 'pubsub.SubscribeWithAvroSchemaExample' Error: Could not find or load main class pubsub.SubscribeWithAvroSchemaExample Caused by: java.lang.ClassNotFoundException: pubsub.SubscribeWithAvroSchemaExample
# 1 楼答案
我无法复制这个问题。我的猜测是,当您运行
mvn clean install
时,它也运行了代码片段中包含的测试。其中一些测试可能需要时间并且可能会失败,这可能会破坏构建过程。如果您只是想测试一个代码段,那么您可以跳过这些测试我的建议是添加一个跳过测试的标志:
更新:检查当前目录。确保在
$HOME/cloudshell_open/java-pubsub-3/samples/snippets
上运行此命令之后,确保构建返回成功,然后通过云编辑器重新运行示例
我采取的步骤是:
git clone https://github.com/googleapis/java-pubsub.git
cd java-pubsub/samples/snippets
mvn clean install -DskipTests
生成结果应如下所示:samples/snippets
工作区李>我能使它正常工作。以下是一个屏幕截图: