I'm trying to migrate my build tool from maven to bazel. I have a java/grpc with a proto file, if I build it with maven all is good, but with bazel I keep facing a problem that happens on the grpc. Maybe my bazel BUILD/WORKSPACE file is not configured properly, I'm not too sure. Any help would be appreciated!
Here is my WORKSPACE file:
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
RULES_JVM_EXTERNAL_TAG = "3.0"
RULES_JVM_EXTERNAL_SHA = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a"
http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)
http_archive(
name = "bazel_skylib",
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
],
)
load("#bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
http_archive(
name = "rules_proto",
sha256 = "73ebe9d15ba42401c785f9d0aeebccd73bd80bf6b8ac78f74996d31f2c0ad7a6",
strip_prefix = "rules_proto-2c0468366367d7ed97a1f702f9cd7155ab3f73c5",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/2c0468366367d7ed97a1f702f9cd7155ab3f73c5.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/2c0468366367d7ed97a1f702f9cd7155ab3f73c5.tar.gz",
],
)
load("#rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()
http_archive(
name = "com_google_protobuf",
sha256 = "e11f901c62f6a35e295b7e9c49123a96ef7a47503afd40ed174860ad4c3f294f",
strip_prefix = "protobuf-3.10.0",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v3.10.0/protobuf-all-3.10.0.tar.gz",
)
http_archive(
name = "googleapi",
sha256 = "51849d3ef693c88eb7692875eb444ef7131502e3fa200f25fc0a37b1e7e55ab5",
strip_prefix = "googleapis-a111a53c0c6722afcd793b64724ceef7862db5b9",
url = "https://github.com/googleapis/googleapis/archive/a111a53c0c6722afcd793b64724ceef7862db5b9.zip",
)
load("#com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
load("#rules_jvm_external//:specs.bzl", "maven")
load("#rules_jvm_external//:defs.bzl", "artifact", "maven_install")
maven_install(
artifacts = [
"com.google.cloud:google-cloud-pubsub:1.92.0",
"com.google.cloud:google-cloud-storage:1.98.0",
"io.grpc:grpc-netty-shaded:1.23.0",
"io.grpc:grpc-protobuf:1.23.0",
"io.grpc:grpc-stub:1.23.0",
"mysql:mysql-connector-java:8.0.17",
"com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.0.15",
"com.zaxxer:HikariCP:3.3.1",
"com.google.inject:guice:4.2.2",
"jaxen:jaxen:1.2.0",
"org.dom4j:dom4j:2.1.1",
"org.slf4j:slf4j-simple:2.0.0-alpha1",
"org.slf4j:slf4j-api:2.0.0-alpha1",
"log4j:log4j:1.2.17",
"com.google.code.gson:gson:2.8.6",
"junit:junit:4.13-beta-3",
"com.google.protobuf:protobuf-java:3.0.0",
"com.google.protobuf:protobuf-java-util:3.0.0",
],
override_targets = {
"com.google.protobuf:protobuf-java": "#com_google_protobuf//:protobuf_java",
},
maven_install_json = "//:maven_install.json",
generate_compat_repositories = True,
repositories = [
"https://jcenter.bintray.com",
],
)
load("#maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()
load("#maven//:compat.bzl", "compat_repositories")
compat_repositories()
maven_install(
artifacts = [
maven.artifact(
group = "com.google.api.grpc",
artifact = "proto-google-common-protos",
version = "1.16.0",
exclusions = [
maven.exclusion(
group = "com.google.protobuf",
artifact = "protobuf-java"
)
]
)
],
maven_install_json = "//:maven_install.json",
generate_compat_repositories = True,
repositories = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
)
load("#maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()
load("#maven//:compat.bzl", "compat_repositories")
compat_repositories()
Here is my BUILD file:
package(default_visibility = ["//visibility:public"])
load("#rules_proto//proto:defs.bzl", "proto_library")
proto_library(
name = "account",
srcs = glob(["src/main/proto/account.proto"]),
deps = ["#googleapi//google/api:annotations_proto"],
)
java_proto_library(
name = "account_proto_java",
deps = [":account"],
)
java_library(
name = "AccountService",
srcs = glob(["src/main/java/**/*.java"]),
resources = glob(["src/main/resources/**"]),
deps = [
"#maven//:com_google_cloud_google_cloud_pubsub",
"#maven//:com_google_cloud_google_cloud_storage",
"#maven//:io_grpc_grpc_netty_shaded",
"#maven//:io_grpc_grpc_protobuf",
"#maven//:io_grpc_grpc_stub",
"#maven//:mysql_mysql_connector_java",
"#maven//:com_google_cloud_sql_mysql_socket_factory_connector_j_8",
"#maven//:com_zaxxer_HikariCP",
"#maven//:com_google_inject_guice",
"#maven//:jaxen_jaxen",
"#maven//:org_dom4j_dom4j",
"#maven//:org_slf4j_slf4j_simple",
"#maven//:org_slf4j_slf4j_api",
"#maven//:log4j_log4j",
"#maven//:com_google_code_gson_gson",
"#maven//:junit_junit",
"#maven//:com_google_guava_guava",
"#maven//:io_grpc_grpc_api",
"#maven//:com_google_protobuf_protobuf_java",
"#maven//:com_google_protobuf_protobuf_java_util",
":account_proto_java",
],
)
I finally run that command: docker run --rm -v /${PWD}:${PWD} -w /${PWD} l.gcr.io/google/bazel:latest build ///...
Some issues that occur:
I always seem to get an error when it's downloading the resources. Here is an example: WARNING: Download from https://maven.google.com/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
For some reason, it doesn't stop there when the 404 appears, towards the end when it comes to build the proto section. I get this error:
ERROR: /c/Users/<username>/projects/Ecommerce-Account-Microservice/BUILD:16:1: Building libAccountService-class.jar (198 source files) failed (Exit 1)
src/main/java/com/app/account/GRPCClient.java:7: error: cannot find symbol
import com.app.account.services.AccountServiceGrpc;
^
symbol: class AccountServiceGrpc
location: package com.app.account.services
src/main/java/com/app/account/GRPCClient.java:20: error: package AccountServiceGrpc does not exist
private final AccountServiceGrpc.AccountServiceBlockingStub blockingStub;
^
src/main/java/com/app/account/server/services/AccountService.java:24: error: cannot find symbol
import com.app.account.services.AccountServiceGrpc;
^
symbol: class AccountServiceGrpc
location: package com.app.account.services
src/main/java/com/app/account/server/services/AccountService.java:39: error: package AccountServiceGrpc does not exist
public class AccountService extends AccountServiceGrpc.AccountServiceImplBase {
^
src/main/java/com/app/account/GRPCClient.java:28: error: cannot find symbol
blockingStub = AccountServiceGrpc.newBlockingStub(channel);
^
symbol: variable AccountServiceGrpc
location: class GRPCClient
src/main/java/com/app/account/server/GrpcServer.java:28: error: no suitable method found for addService(AccountService)
.addService(AccountService.getInstance())
^
method ServerBuilder.addService(ServerServiceDefinition) is not applicable
(argument mismatch; AccountService cannot be converted to ServerServiceDefinition)
method ServerBuilder.addService(BindableService) is not applicable
(argument mismatch; AccountService cannot be converted to BindableService)
where CAP#1 is a fresh type-variable:
CAP#1 extends ServerBuilder<CAP#1> from capture of ?
src/main/java/com/app/account/server/services/AccountService.java:57: error: method does not override or implement a method from a supertype
#Override
^
src/main/java/com/app/account/server/services/AccountService.java:65: error: method does not override or implement a method from a supertype
#Override
^
src/main/java/com/app/account/server/services/AccountService.java:223: error: method does not override or implement a method from a supertype
#Override
^
src/main/java/com/app/account/server/services/AccountService.java:273: error: method does not override or implement a method from a supertype
#Override
^
INFO: Elapsed time: 373.098s, Critical Path: 44.04s
INFO: 358 processes: 353 processwrapper-sandbox, 5 worker.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
I'm not too sure what is going on or what I'm doing wrong at that point, that's why I'm showing all the code.
Thanks a lot!
Mark
If you want to use multiple maven_install declarations, you need unique names for each of them. See documentation here.
I always seem to get an error when it's downloading the resources. Here is an example: WARNING: Download from https://maven.google.com/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
It looks like you don't actually use maven.google.com for any of the artifacts. Remove that from your maven_install.repositories lists and re-run artifact pinning for them.
For the missing GRPC classes, it looks like you're missing a java_grpc_library between java_library and java_proto_library. Example.
I am trying to connect java with R using Rserve
Java: 1.8.0_151
R: 3.5.0
OS: Mac 10.13.4 HighSierra
To connect R with Java, I typed the following on RStudio
install.packages("Rserve")
library(Rserve)
Rserve(args="--no-save")
things went smooth and I was so happy about it.
Then I jumped back to Java (Java Eclipse so to speak) and continued typing. Here is what I've done on Eclipse
package rserve;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.REngineException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
public class WordCloud1 {
public static void main(String[] args) throws REngineException,
REXPMismatchException {
RConnection c = new RConnection();
String path = "/Users/JinhoShin/Desktop/study/R/r_temp2";
String file = "seoul_new.txt";
c.parseAndEval("library(KoNLP)");
c.parseAndEval("useSejongDic()");
c.parseAndEval("library(wordcloud)");
c.parseAndEval("library(RColorBrewer)");
c.parseAndEval("setwd('" + path + "')");
c.parseAndEval("data1=readLines('" + file + "')");
c.parseAndEval("data2 = sapply(data1,extractNoun,USE.NAMES=F)");
c.parseAndEval("data3 = unlist(data2)");
c.parseAndEval("data3=gsub('seoul','',data3)");
c.parseAndEval("data3=gsub('request','',data3)");
c.parseAndEval("data3=gsub('place','',data3)");
c.parseAndEval("data3=gsub('transportation','',data3)");
c.parseAndEval("data3=gsub(' ','',data3)");
c.parseAndEval("data3=gsub('-','',data3)");
c.parseAndEval("data3=gsub('OO','',data3)");
c.parseAndEval("write(unlist(data3),'seoul_2.txt')");
c.parseAndEval("data4 = read.table('seoul_2.txt')"); ########this is what blows me up
c.parseAndEval("wordcount=table(data4)");
c.parseAndEval("palete = brewer.pal(9,'Set3')");
c.parseAndEval(
"wordcloud(names(wordcount),freq = wordcount,scale=c(5,1),rot.per=0.25, min.freq = 1," +
" random.order=F, random.color = T, colors=palete)");
c.parseAndEval("savePlot('0517seoul.png', type = 'png')");
c.parseAndEval("dev.off()");
c.close();
}
}
as you notice from the code
c.parseAndEval("data4 = read.table('seoul_2.txt')"); => at rserve.WordCloud1.main(WordCloud1.java:30)
I have no idea why it can't read my text file despite the fact that it could write that file.
This is what Java Eclipse console keeps showing me
Exception in thread "main" org.rosuda.REngine.REngineException: eval failed
at org.rosuda.REngine.Rserve.RConnection.parseAndEval(RConnection.java:499)
at org.rosuda.REngine.REngine.parseAndEval(REngine.java:108)
at rserve.WordCloud1.main(WordCloud1.java:30)
Caused by: org.rosuda.REngine.Rserve.RserveException: eval failed
at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:261)
at org.rosuda.REngine.Rserve.RConnection.parseAndEval(RConnection.java:497)
... 2 more
and this is what RStudio keeps showing me
Error: long vectors not supported yet: qap_encode.c:36
Fatal error: unable to initialize the JIT
I tried everything I could do to resolve this issue, but still I am on the same spot.
How can I suppress the rJava output to the console in the following example?
library(rJava)
TC <- J("edu.cens.spatial.RTileController")
dummy <- capture.output(suppressWarnings(suppressMessages(
res <- TC$getInstance(type="osm-bw")$getTileValues(4389,2691,13)
)))
Despite capture.output, I still get the following in the console:
java.lang.NullPointerException
at edu.cens.spatial.RTileController.getTileValues(RTileController.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at RJavaTools.invokeMethod(RJavaTools.java:386)
Edit: In pure R Console (without Rstudio), I get no messages (but I have to call library("OpenStreetMap") first). So this might be an Rstudio issue after all ... The question is now: how can I suppres Java output to the R console in Rstudio? Is it possible to do this when calling osmtile as outlined below?
PS1: It works for osm instead of osm-bw.
PS2: I came across this via
tile <- OpenStreetMap::osmtile(x=4389,y=2691,zoom=13,type="osm-bw")
In my case, something like this works - NullPointer message is suppressed:
> s <- .jcall(obj, returnSig="V", method="nullcall")
Error in .jcall(obj, returnSig = "V", method = "nullcall") :
java.lang.NullPointerException: Exception
> suppressMessages(s <- .jcall(obj, returnSig="V", method="nullcall"))
To reproduce this code do following:
Create file (from within R)
dir.create("utils")
dir.create("target")
cat('package utils;
public class RUsingStringArray {
public void nullcall() throws NullPointerException {
throw new NullPointerException("Exception");
}
public static void main(String [] arg) {
RUsingStringArray obj = new RUsingStringArray();
obj.nullcall();
}
}', file="utils/RUsingStringArray.java")
Compile java code (in cmd / terminal, last line won't work on windows)
javac -d target utils/*.java
java -cp target utils/RUsingStringArray
Exception in thread "main" java.lang.NullPointerException: Exception
at utils.RUsingStringArray.nullcall(RUsingStringArray.java:19)
at utils.RUsingStringArray.main(RUsingStringArray.java:24)
export CLASSPATH=`pwd`/target
Inside R
library(rJava)
.jinit("C:/path_to_folder/target") # leave empty if CLASSPATH was set
obj <- .jnew("utils.RUsingStringArray")
s <- .jcall(obj, returnSig="V", method="nullcall")
suppressMessages(s <- .jcall(obj, returnSig="V", method="nullcall"))
Error in .jcall(obj, returnSig = "V", method = "nullcall") :
java.lang.NullPointerException: Exception
I have a child java project which has groovy files added in classpath using eclipse. Parent java project triggers some functionality in child which uses Groovy library to run the scripts. So import works fine in eclipse environment with opened child project but if I run it from command line or if I close child project then I get groovy compilation error at import statement. How can I resolve this ? I want to avoid using evaluate() method.
Following is my master groovy:
package strides_business_script
abstract class Business_Script extends Script {
//some stuff
}
Following is the another groovy:
import static strides_business_script.StridesBusiness_Script.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
String Key = Part_Product_PartDetails
boolean containsData = checkIncomingMessage(Key)
if(containsData) {
def edgeKeyList = [PPR]
JSONArray partDetails = appendEdgeValueToMsg(edgeKeyList,Key,vertex,messageIterator);
//deleteMessages(Key);
JSONObject jsonObject = constructInfoWithPropertyJSON("NAME,PRODUCTTYPE,FGTYPE,UOM,ITEMCLASSIFICATIONBYMARKET");
jsonObject.put("PARTS",partDetails);
send(Product_AggPO_ProductDetails,convertJSONToString(jsonObject));
}
Edit:
My master script Business_Script.groovy resides in scripts/strides_business_script/ folder. All other scripts are in scripts/StridesComputationScripts/ folder and they import the Business_Script.groovy.
I run the application with remote debugging enabled like this:
java -cp "./lib/*:./scripts/strides_business_script/Business_Script.groovy" -Xdebug -Xrunjdwp:transport=dt_socket,address=6969,server=y -Dhibernate.cfg.xml.path=./conf/hibernate.cfg.xml -Dlog4j.configuration=file:./conf/log4j.properties com.biglabs.dataExtractor.dataDump.DataDumpDriver 7
and here I am trying to parse all computation scripts.
for (String scriptName : files) {
Script script = groovyShell.parse(new File(
SCRIPT_PLACED_AT + Constants.SLASH
+ SCRIPT_FILE_FOLDER + Constants.SLASH
+ scriptName));
scriptMping.put(scriptName, script);
}
It throws following exception while parsing using groovy shell:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/manoj/strides/release/strides/scripts/StridesComputationScripts/PRODUCT-script.groovy: 2: unable to resolve class strides_business_script.StridesBusiness_Script
# line 2, column 1.
import static strides_business_script.Business_Script.*;
^
/home/manoj/strides/release/strides/scripts/StridesComputationScripts/PRODUCT-script.groovy: 2: unable to resolve class strides_business_script.StridesBusiness_Script
# line 2, column 1.
import static strides_business_script.Business_Script.*;
^
2 errors
Fixed it by adding script path in comiler configuration:
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
String path = SCRIPT_PLACED_AT;
if(!SCRIPT_PLACED_AT.endsWith("/")){
path = path+ "/";
}
compilerConfiguration.setClasspath(path);
GroovyShell groovyShell = new GroovyShell(
compilerConfiguration);
for (String scriptName : files) {
Script script = groovyShell.parse(new File(
SCRIPT_PLACED_AT + Constants.SLASH
+ SCRIPT_FILE_FOLDER + Constants.SLASH
+ scriptName));
scriptMping.put(scriptName, script);
}
Hi Team,
I'm new to Antlr and I have spent 4 days trying to learn, install, run tutorials and integrate with my IDE. :(
I can run this [tutorial][1] in the Terminal successfully. My goal now is to run the same tutorial in Netbeans with AntlrWorks2 I have cannibalised the Main from [Here][2].
The code compiles, but when I run I get an "java.lang.ExceptionInInitializerError" from init of the Lexer.
1: http://www.antlr.org/wiki/display/ANTLR4/Getting+Started+with+ANTLR+v4
2: http://www.certpal.com/blogs/2011/01/antlr-tutorial-hello-antlr/)
Grammar:
grammar Split;
#header {
package PlayGround.AutoGen;
}
hi : HELLO ID ; // match keyword hello followed by an identifier
ID : [a-z]+ | [A-Z]+; // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
HELLO : '[H|h]ello';
Main:
public class MyMain {
public static void main(String args[]) {
new MyMain().MyAttempt();
}
public void MyAttempt() {
try {
String string = "Hello World";
CharStream charStream = new ANTLRInputStream(string);
/*Line 28*/ SplitLexer lex = new SplitLexer(charStream); /*Line 28*/
org.antlr.v4.runtime.CommonTokenStream tokens;
tokens = new org.antlr.v4.runtime.CommonTokenStream(lex);
SplitParser parser = new SplitParser(tokens);
SplitParser.HiContext split = parser.hi();
String toString = split.toString();
System.out.println(toString);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Error:
run:
Exception in thread "main" java.lang.ExceptionInInitializerError
at PlayGround.MyMain.MyAttempt(MyMain.java:28)
at PlayGround.MyMain.main(MyMain.java:21)
Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 2 (expected 3).
at org.antlr.v4.runtime.atn.ATNSimulator.deserialize(ATNSimulator.java:132)
at PlayGround.AutoGen.SplitLexer.<clinit>(SplitLexer.java:78)
... 2 more
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 2 (expected 3).
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
ANSWER: antlr4: ATN version 2 expected 3
It sounds like there might be a version issue. ANTLR generates serialized ATN (augmented transition networks) that have a special format that can change from version to version like 4.0 to 4.1. it's possible that your loading source code generated from the command line in one version and the latest AW2 in NetBeans is trying to read it with a different version.
"Your parser was generated with ANTLR 4.0, but you are trying to execute it with ANTLR 4.1. The most likely cause of this is using ANTLRWorks 2.0 to generate the parser, which internally uses ANTLR 4.0. I'm in the process of releasing ANTLRWorks 2.1 which will correct this mismatch." - 280Z28
Answer is Here