Cannot compile with protocol buffers 3.1.0 - java

I downloaded/installed protocol buffers 3.1.0 and used protoc to compile a .proto file which generated a .java class for me.
With this change, everything works/compiles.
Then I replaced the avro jars with their latest versions and tried to compile my project again, but no luck, it's complaining this error:
# Compile: pregen/media.proto
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:828: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
location: class Descriptors
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:2669: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
location: class Descriptors
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:4131: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
location: class Descriptors
3 errors
I did a lot search/research and still no luck, also looked at this most relevant post: Problems using protobufs with java and scala
and then I compiled my generated .java file along with protobuf.3.1.0.jar into a new jar and placed it under my lib/, but the project still cannot compile.
Any help on how to resolve this issue please?
(I'm using an open-source project to benchmark Java serialzation performance, and I've posted a more detailed question/issue there as well.)

One of the authors of that open source projects helped me resolve the issue, copy the solution here as well:
"The problem was that avro-tools-1.8.1.jar bundles some of the Protobuf
class files (ugh). The bundled class files aren't compatible with the ones
our generated Protobuf code relies on.
We're pretty fast and loose with what's on the classpath; we just include
"lib/*.jar". It would be nice to be more precise with dependencies at some
point.
But as a quick fix, I put avro-tools-1.8.1.jar in "lib/extra/", so it won't
get picked up by default. The Makefile now specifically references that
JAR only when we need to run the Avro code generator."
Thanks.

Related

warnings can't find CharStreams after moving project

I moved my antlr4 based project which uses 6 different grammers to a different folder (and github depository). Now when I try to rebuild the Java project in I'm getting errors such as
Error:(30, 39) java: cannot find symbol
symbol: variable CharStreams
location: class com.applitools.ekb.PhpExtractInterfaceTool
even though the code includes
import org.antlr.v4.runtime.*;
and in a different grammar, it is even more explicit
import org.antlr.v4.runtime.CharStreams;
In the latter case, InteliJ (2019) colors CharStreams in red and says "cant resolve CharStreams"
All I did is copy the project over and all works as expected in the original project. I tried to unistall and then reinstall the antlr4 plugin - didn't help.

JAR inclusion not working

I am learning how to create an RMI system, and I compiled the shared classes into a .jar, but when I try to include it, the following error occurs:
javac -cp compute.jar Client.java
Client.java:6: error: package rmi.interfaces does not exist
import rmi.interfaces.Tasks;
^
Client.java:17: error: cannot find symbol
Tasks stub = (Tasks) registry.lookup("Tasks");
^
symbol: class Tasks
location: class Client
Client.java:17: error: cannot find symbol
Tasks stub = (Tasks) registry.lookup("Tasks");
^
symbol: class Tasks
location: class Client
3 errors
The classes it needs are inside the jar, but for some reason it can't find them. How can I fix this?
The message says that rmi.interfaces package is not on your classpath. In you example this means not in compute.jar. You could verify that by typing zipinfo -1 compute.jar to see what entries are inside the JAR.
You really should setup a build tool for your project. You really shouldn't be compiling Java by hand unless you are learning what is javac. If you want to try Maven you can clone rm5248/Java-RMI-Example to see how to set up an RMI project with independent client and server modules.

STSheetViewType class is missing in poi-ooxml-schemas-3.14 JAR

Currently I'm trying to implement the code given in the answer to this question:
CTSheetView view = sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0);
view.setView(STSheetViewType.PAGE_LAYOUT);
but the poi-ooxml-schemas (version 3.14) JAR file does not contain the class STSheetViewType. I delved into the poi-ooxml-schemas JAR file (using 7ZIP) and found that the class file STSheetViewType$Enum.class existed within the path:
org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetViewType$Enum.class
But (If I'm not mistaken) The '$' signifies an inner/nested class, meaning the STSheetViewType Enum is encapsulated within another class. I checked the documentation on the STSheetViewType class in an older version of poi-ooxml-schemas (version 1.1) here and found that the class STSheetViewType contained an inner Enum STSheetViewType.Enum.
This also seems to be confirmed by the errors I'm receiving from within Eclipse. I get these errors when using the code shown above:
"STSheetViewType cannot be resolved to a variable"
"The type org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetViewType cannot be resolved. It is indirectly referenced from required .class files"
Which further makes me believe that the STSheetViewType.Enum is missing its parent STSheetViewType class file. But why? I checked the documentation on the new version of poi-ooxml-schemas-3.14 and found no mention of STSheetViewType in the changelogs. I've downloaded the binary zip file for POI several times to ensure that my download wasn't faulty, I even downloaded the source and tried building the JARs but the class file is missing each time.
I found that a class STSheetViewType with seemingly the same functionality is held in another Jar file here but I can't seem to import the class correctly. Is such a thing even possible? Or must the class file come with the poi-ooxml-schemas-3.14 JAR file?
Ultimately I'd like to find out how to make the above code compatible with the current version of poi-ooxml-schemas-3.14 JAR. Any information or insight shed on that would be greatly appreciated.
As pointed out by #AxelRichter and the FAQ, Apache POI 3.14 and above uses a subset of classes from the ooxml-schemas-1.3.jar. You need to get that jar file and include in your classpath instead of poi-ooxml-schemas-3.14.jar. POI only provides the ooxml schemas classes it requires. When you begin to directly call ooxml schema classes in your own code, you most likely have to get the full jar that has all ooxml schemas classes to avoid this kind of issue you have. You can get the jar from maven central:
http://central.maven.org/maven2/org/apache/poi/ooxml-schemas/1.3/
See also the FAQ entry at http://poi.apache.org/faq.html#faq-N10025

Finding jar dependencies for eclipse/jdt in Java

I'm trying to compile Eclipse JDT - Abstract Syntax Tree (AST) and the Java Model - Tutorial using command line.
I came up with this command line based on the name match in plugins directory in eclipse indigo.
javac -cp .:\
org.eclipse.core.runtime_3.7.0.v20110110.jar:\
org.eclipse.equinox.common_3.6.0.v20110523.jar:\
org.eclipse.core.commands_3.6.0.I20110111-0800.jar:\
org.eclipse.core.resources_3.7.100.v20110510-0712.jar:\
org.eclipse.jface.text_3.7.1.r371_v20110825-0800.jar:\
org.eclipse.jdt.core_3.7.1.v_B76_R37x.jar:\
org.eclipse.jdt_3.7.1.v201109091335.jar \
SampleHandler.java
The problem is that I still get these 4 errors.
SampleHandler.java:19: cannot find symbol
symbol : class Document
location: package org.eclipse.jface.text
import org.eclipse.jface.text.Document;
^
SampleHandler.java:28: cannot access org.eclipse.core.runtime.jobs.ISchedulingRule
class file for org.eclipse.core.runtime.jobs.ISchedulingRule not found
IProject[] projects = root.getProjects();
^
SampleHandler.java:87: cannot find symbol
symbol : class Document
location: class handlers.SampleHandler
Document doc = new Document(unit.getSource());
^
SampleHandler.java:87: cannot find symbol
symbol : class Document
location: class handlers.SampleHandler
Document doc = new Document(unit.getSource());
^
4 errors
I had much more errors, but with the help of this hint, I could add org.eclipse.equinox.common_3.6.0.v20110523.jar to remove many errors.
It seems like that the jar name might not reflect the package import name.
How can I know what jar files should be added to remove the errors?
I found http://www.jarfinder.com pretty useful. Using this site, I could give the class name to find the jar name for available eclipse releases.
For example, I could search org.eclipse.jface.text.Document
By clicking the class, I could identify the name of the jar file.
Even though the newest eclipse information is not available, I could guess the jar name.

Cannot Find Symbol createAccessBeans(java.util.Collection) when Compiling EJB 1.1 IBM Commerce Project

I am trying to "Mavenize" our existing Commerce solution. However, I am getting a weird error when I try to run mvn compile I get the following error.
[ERROR] /home/user/tmp/IBM/WCDE_ENT70/workspace/WebSphereCommerceServerExtensionsData/ejbModule/org/ecommerce/wcs/changerequest/ChangeRequestAccessBean.java:[347,32] cannot find symbol
[ERROR] symbol : method createAccessBeans(java.util.Collection)
[ERROR] location: class org.ecommerce.wcs.changerequest.ChangeRequestAccessBean
When I check the class it is related to the com.ibm.ivj.ejb.runtime.AbstractEntityAccessBean class which IBM has neglected to include JavaDoc for anywhere. I look into eclipse and it shows me the method in question was correct using code complete, however, it still fails with maven.
I am wondering if it isn't a customisation to the IBM jre (I am not using that for this POC) and if there is no way around it (short of extending the class and reimplementing).
Anyone?
Problem had to do with multiple imports of different versions of the same dependency. Now this has been resolved.

Categories

Resources