Finding jar dependencies for eclipse/jdt in Java - 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.

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.

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())));

vaadin7: com.vaadin.ui.UI class isn't visible

I have a vaadin6 application that I have to upgrade to vaadin7.
I used this document to understand vaadin6 to vaadin7 migrating:
https://vaadin.com/wiki/-/wiki/Main/Migrating+from+Vaadin+6+to+Vaadin+7
Then I tried to build the application (with maven2) with vaadin7.0.0.alpha3 repository.
Obviously many errors appears because of the differences between vaadin6 API and vaadin7 API.
One of those errors that I have to correct is:
cannot find symbol
symbol : method getMainWindow()
location: class com.vaadin.Application
What I understood is that I have to use com.vaadin.ui.UI instead of com.vaadin.Application.
But the problem is that when I add
import com.vaadin.ui.UI;
Then I tried to build again this error appears:
[ERROR] D:\aperte-workflow\core\gui-commons\src\main\java\org\aperteworkflo\util\vaadin\VaadinUtility.java:[53,20] cannot find symbol
symbol : class UI
location: package com.vaadin.ui
I'm sure that I'm using vaadin7.0.0 repository. I checked also that com.vaadin.ui.UI class exists in the repository that I'm using:
https://vaadin.com/api/7.0.0/com/vaadin/ui/UI.html
So what's the problem?

Categories

Resources