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.
Related
So I was following this tutorial:
https://spring.io/guides/gs/maven/
I cloned their repositories for the software for fear of mistyping something.
The code does not work when I compile Greeter.java using javac and then use java to run HelloWorld.java file It gives me the following error:
HelloWorld.java:5: error: cannot find symbol
Greeter greeter = new Greeter();
^
symbol: class Greeter
location: class HelloWorld
HelloWorld.java:5: error: cannot find symbol
Greeter greeter = new Greeter();
^
symbol: class Greeter
location: class HelloWorld
2 errors
I tried explicitly importing Greeter into HelloWorld using
ìmport hello.Greeter
The code works fine when I run it without the package hello;statements.
Any idea why I am getting this error??
So I followed through with the tutorial and using mvn package command and the jar file generated the project works.
So is this issue with trying to compile it with java command in the command line.
Adding directory structure of the project
pom.xml src target
./src:
main
./src/main:
java
./src/main/java:
hello
./src/main/java/hello:
Greeter.java HelloWorld.java
I assume you try to compile the sources while you're in the directory src/test/java/hello. That's the wrong directory, you have to do it from directory src/test/java and pass the directory (i.e. package) to the compiler, e.g.
javac hello/*.java
Another reason might be that you haven't compiled Greeter.java, so the compiler doesn't find the class-file while compiling Hello.java. Above command should solve that.
If you have a main method in hello run
java hello/name-of-file.java
to run your main method.
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.
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
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())));
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.