我在JDK 11上运行了一个模块化的基于jersey的微服务,它可以很好地部署到Google App Engine上。代码可以从这里下载(或者克隆主项目并切换到3.1tag):https://github.com/Leejjon/SimpleJerseyService/releases/tag/3.1
现在,我想添加对Google Cloud Datastore API的访问(该API在我之前的非模块化Java 8项目中工作)。所以我添加了maven依赖:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore</artifactId>
<version>1.80.0</version>
</dependency>我将requires google.cloud.datastore;添加到我的模块-info.java中。
mvn clean install运行良好,但是当我通过mvn exec:exec或java -p simple-service-1.0-SNAPSHOT.jar;appengine-staging/ -m myModule/com.example.Main localhost运行它时
我得到了:
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules grpc.context and grpc.api export package io.grpc to module org.apache.httpcomponents.httpclient我可以在我的module-info.java中做些什么来解决这个问题吗?
在阅读了以下帖子后:https://blog.codefx.org/java/java-9-migration-guide/#Split-Packages https://blog.codefx.org/java/jsr-305-java-9/#Modular-Project Modules A and B export package some.package to module C in Java 9
我怀疑这个google-cloud-datastore库还没有为Java模块系统做好准备。我会在Google Cloud Client API github上发布一个问题,提到这个stackoverflow帖子。
发布于 2019-07-02 05:15:35
在Google将有效的module-info.java文件添加到google-cloud-datastore和google-cloud-core maven依赖项(我在他们的github here上报告了一个问题)之前,解决方法是使用旧的类路径。
在我的项目中,将exec-maven-plugin的配置从:
<configuration>
<executable>java</executable>
<arguments>
<argument>-p</argument> <!-- or -p -->
<!-- automatically creates the modulepath using all project dependencies,
also adding the project build directory -->
<modulepath/>
<argument>-m</argument> <!-- or -m -->
<argument>myModule/com.example.Main</argument>
<argument>localhost</argument>
</arguments>
</configuration>至
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>com.example.Main</argument>
<argument>localhost</argument>
</arguments>
</configuration>使用mvn -X exec:exec将显示完整的java命令,其中包括所有必需的jars。The entire java command will be super long like this pastebin.
发布于 2019-07-11 17:32:15
通过排除依赖项来“修复”我的项目的pmakani from github managed:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore</artifactId>
<version>1.80.0</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</exclusion>
</exclusions>
</dependency>访问数据存储似乎是可行的,但是日志中仍然包含这样的错误: java.lang.reflect.InaccessibleObjectException: Unable to make field protected volatile java.io.InputStream java.io.FilterInputStream.in accessible: module java.base未向模块数据“打开java.io”
完整日志:https://pastebin.com/e431R7pW
我认为Google仍然应该让他们的gcloud库(以及它们所依赖的所有依赖项)模块化。
https://stackoverflow.com/questions/56828520
复制相似问题