I am trying to implement a shell script that generates the Java classes for a given set of Protobuf files. The generated classes are then grouped into a JAR which is to be imported by any Java project that needs to use these protobuf generated classes or gRPC stubs.
The script roughly looks like bellow:
# Generate java classes from .proto files
protoc -I ${PROTO_REPO_PATH}
--plugin=protoc-gen-grpc-java=$GEN_GRPC_JAVA_PATH \
--grpc-java_out=$JAVA_OUT --java_out=$JAVA_OUT \
$FILES
JAR_FILE="$JAVA_OUT/$SERVICE_NAME-$API_VERSION.jar"
# Create JAR from generated classes
jar cf "$JAR_FILE" -C "$JAVA_OUT" .
# Install JAR in local repository
mvn install:install-file -Dfile=$JAR_FILE -Dpackaging=jar -DgroupId=foo.grpc -DartifactId=$SERVICE_NAME-proto -Dversion=1.0
# Clean generated java code
rm -r $JAVA_OUT
After execution, the JAR is present in ~/.m2/repository
and, using jar tf foo-service-1.0.jar
, I verified that all the generated classes are inside it.
Yet I cannot import any of those classes in a Java project on any IDE I tried (i.e. IntelliJ, VScode). The JAR appears empty inside the IDE browser yet autocompletion works when importing the parrent packages but fails when trying to import a specific class.
I tried proposed answers on this similar but different question but without any success.