Ignore unresolved symbols when compiling java with javac - java

I am using Google Plugin in STS and it reports missing class. I decided to go a quick and dirty way and download the class, compile it and put it into plugin folder or jar file.
The class is here: Java2HTMLEntityReader.java
When I compile, I of course get some errors:
Java2HTMLEntityReader.java:19: error: package org.eclipse.jdt.internal.compiler.parser does not exist
import org.eclipse.jdt.internal.compiler.parser.*;
^
Java2HTMLEntityReader.java:28: error: cannot find symbol
public class Java2HTMLEntityReader extends SubstitutionTextReader {
^
symbol: class SubstitutionTextReader
Java2HTMLEntityReader.java:58: error: cannot find symbol
setSkipWhitespace(false);
^
symbol: method setSkipWhitespace(boolean)
location: class Java2HTMLEntityReader
Java2HTMLEntityReader.java:69: error: cannot find symbol
c = nextChar();
^
symbol: method nextChar()
location: class Java2HTMLEntityReader
Java2HTMLEntityReader.java:105: error: cannot find symbol
} else if (!ScannerHelper.isWhitespace((char) c)) {
^
symbol: variable ScannerHelper
location: class Java2HTMLEntityReader
Note: Java2HTMLEntityReader.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
That's because I didn't give the java compiler refference to the package. And I don't intend to! I want to compile it with those errors, I assume it will work when I put it on the correct classpath.

If you'd use the Eclipse compiler to compile that class, you could request creation of .class files despite compile errors. On the command line this is done using the option -proceedOnError. To the best of my knowledge javac does not have such an option.
Mind you, that unresolved types in API positions (super types, method signatures) may render the resulting class file useless.
I don't really see a good reason for hacking such a stub .class file for compilation. If you have the corresponding jar file available at runtime, you should really use the same jar also during compilation.

Successful compilation means there should be no errors in the source code.
If your code contains compilation errors it cannot compile and will not produce a .class file

Related

Javac complains that can not see jre library classes during compilation

I am trying to compile java classes using javac. The project uses ByteInputStream class that is located in java_version/jre/lib/rt.jar file(in package com.sun.xml.internal.messaging.saaj.util). javac compilter complains that can't find that class. I tried to include all library classes on during compilation(lib1:lib2:lib3:etc) but still no result.
Here is error message:
package com.sun.xml.internal.messaging.saaj.util does not exist
cannot find symbol : class ByteInputStream
Any ideas?

Protocol Buffers source is missing files

For background, see: How to compile google-fhir proto files
There seem to be missing .java files when compiling using protoc. I do not see those files here: https://github.com/google/protobuf/tree/master/java/core/src/main/java/com/google/protobuf either. Of course, protoc generated additional files such a Patient.java that were not in the linked folder above. I just need it to compile.
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30950: error: cannot find symbol
public com.google.fhir.stu3.proto.CodeableConceptOrBuilder getJurisdictionOrBuilder(
^
symbol: class CodeableConceptOrBuilder
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30956: error: cannot find symbol
private java.util.List<com.google.fhir.stu3.proto.CodeableConcept> topic_;
^
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30964: error: cannot find symbol
public java.util.List<com.google.fhir.stu3.proto.CodeableConcept> getTopicList() {
^
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30974: error: cannot find symbol
public java.util.List<? extends com.google.fhir.stu3.proto.CodeableConceptOrBuilder>
.... ^
100 errors.
UPDATE
Running examples/protogen/generate-proto.sh returns:
FAILED: Build did NOT complete successfully
generate-descriptors.sh: line 29: ../../bazel-bin/java/ProtoGenerator: No such file or directory
It looks like bazel did not get run correctly, because ProtoGenerator is not in hazel-bin. I ran bazel build, in the root directory where there is a BUILD file. It complained about a workspace, to which I was told to create an empty WORKSPACE file. When done, there were no errors and bazel-bin was created. Are there additional parameters than bazel build. Also, I thought I saw more than one BUILD file in addition to the one in proto/stu3, but maybe I am mistaken.

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.

Cannot compile with protocol buffers 3.1.0

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.

Javac not registering class path and methods correctly, symbol not found

I'm trying to use Apache Commons StringEscapeUtils. I've got this line of code in my import statement,
import org.apache.commons.lang3.StringEscapeUtils;
I've downloaded apache commons lang, extracted it and moved:
commons-lang3-3.4.jar
(Note: just the .jar file, not anything else that came with it. Not sure if it matters) into my lib directory where I store all of my other .jar files.
and I'm compiling it with:
javac -cp .:lib/* Main.java
However, javac is giving me this error:
./FactualResultDeserializer.java:43: error: cannot find symbol
factualObject.setTitle(unescapeHtml(unescapeJava(resultActivity.get(TITLE).getAsString())));
^
symbol: method unescapeJava(String)
location: class FactualResultDeserializer
./FactualResultDeserializer.java:51: error: cannot find symbol
categories[j] = unescapeHtml(unescapeJava(catArray.get(0).getAsJsonArray().get(j).getAsString()));
^
symbol: method unescapeJava(String)
location: class FactualResultDeserializer
2 errors
It did not give me an error for unescapeHtml which is from the same StringEscapeUtils package.
I have tried clearing the .class files to recompile. It did not solve the problem, help would be appreciated.
Thanks in advance!
Prefix the method calls with the name of the class to avoid any ambiguities. There is no unescapeHtml in org.apache.commons.lang3.StringEscapeUtils, use unescapeHtml3 or unescapeHtml4.
factualObject.setTitle(
StringEscapeUtils.unescapeHtml4(
StringEscapeUtils.unescapeJava( resultActivity.get(TITLE).getAsString())));

Categories

Resources