原件的一部分:

message GetTaskConfigsReply{
  message ConfigFileInfo{
    string name = 1;
    string path = 2;
    string modified_time = 3;
  }
  repeated ConfigFileInfo configs = 1;
}

大家好,我是Java新手,我想用GRPC远程控制另一个C#应用程序,这个C#应用程序会发送这个Java应用程序GetTaskConfigsReply,C#应用程序运行得很好,但是在Java中,ConfigFileInfo不能生成,我找不到这个类,该怎么修复呢?谢谢!

-pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>xx</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>xx</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

 <!-- <repositories>
    <repository>
        <id>google-maven</id>
        <name>Google Maven Repository</name>
        <url>https://maven.pkg.github.com/grpc/grpc-java</url>
    </repository>
</repositories> -->


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-netty-shaded</artifactId>
      <version>1.41.3</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-protobuf</artifactId>
      <version>1.41.3</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-stub</artifactId>
      <version>1.41.3</version>
    </dependency>
    <dependency> <!-- necessary for Java 9+ -->
      <groupId>org.apache.tomcat</groupId>
      <artifactId>annotations-api</artifactId>
      <version>6.0.53</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to
      parent pom) -->
      <plugins>
        <!-- clean lifecycle, see
        https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see
        https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see
        https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.7.1</version>
      </extension>
    </extensions>
    <plugins>
      <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.6.1</version>
        <configuration>
          <protocArtifact>com.google.protobuf:protoc:3.19.6:exe:${os.detected.classifier}</protocArtifact>
          <pluginId>grpc-java</pluginId>
          <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.41.3:exe:${os.detected.classifier}</pluginArtifact>
          <clearOutputDirectory>false</clearOutputDirectory>
          <outputDirectory>${basedir}/src/main/java</outputDirectory>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>compile-custom</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

原件:

syntax = "proto3";

service RemoteControl {
  rpc GetTaskConfigs(GetTaskConfigsRequest) returns (GetTaskConfigsReply);
  
}

message GetTaskConfigsRequest {

}

message GetTaskConfigsReply{
  message ConfigFileInfo{
    string name = 1;
    string path = 2;
    string modified_time = 3;
  }
  repeated ConfigFileInfo configs = 1;
}

Java代码:

 private static List<ConfigFileInfo> GetTaskConfigs(RemoteControlBlockingStub remoteControlBlockingStub) {
        GetTaskConfigsRequest request = GetTaskConfigsRequest.newBuilder().build();

        GetTaskConfigsReply reply = remoteControlBlockingStub.getTaskConfigs(request);
        List<ConfigFileInfo> configFileInfos = new ArrayList<ConfigFileInfo>();
        for (int i = 0; i < reply.getConfigsCount(); i++) {
            configFileInfos.add(reply.getConfigs(i));
        }
        return configFileInfos;
    }

推荐答案

好的,这应该是用Maven来编译的,现在一切都好了.

Java相关问答推荐

我的scala文件失败了Scala.g4 ANTLR语法

Java中后期绑定的替代概念

确定Java中Math.Ranb()输出的上限

是否在允许数组元素为空时阻止 idea 为空性警告?

在Java中,在单个逻辑行中连接列表和单个元素的正确方法是什么?

基于调车场算法的科学计算器

Kotlin内联互操作:强制装箱

如何解释Java中for-each循环中对Iterable的强制转换方法引用?

匹配一组字符或另一组字符

S,要对Java复制构造函数深度克隆所有属性进行单元测试,最可靠的方法是什么?

SpringBoot:在条件{Variable}.isBlank/{Variable}.isEmpty不起作用的情况下进行路径变量验证

如何使这两种方法合二为一?

在JDK Flight Recorder中只记录单个线程

Oracle中从JSON中提取和插入数据

在Eclipse中可以使用外部字体吗?

为什么没有加载java.se模块?

如何将RESTAssured';S的Http标题转换为<;字符串、字符串和>的映射?

Java 21内置http客户端固定运营商线程

spring 更新多项管理关系

java.lang.ClassCastException:com.google.firebase.FirebaseException无法转换为com.google.fire base.auth.FirebaseAuthException