Solrj Imports - package not found - java

I am trying to use SolrJ in Netbeans for my java application.
In the project library, I imported all the SolrJ java files :
org.apache.solr.client.solrj
But in my code, when I add :
import org.apache.solr.client.solrj;
It doesn't work and it says: package does not exist.
I have tried several methods but the package is never found.
What am I doing wrong here?

First, I don't think you can write the import that way. It should be more like this:
import org.apache.solr.client.solrj.*;
I don't know if Netbeans has an auto-import feature (have never used this IDE), but you might try to see if you can get Netbeans to auto-import something from solrj. Try SolrServer or QueryResponse.
Also, are you using Maven? Maven should make all this a little easier for you.
If that fails, I'm not sure what it could be, but here's a link to one or two people who had a problem very similar to yours: https://netbeans.org/projects/cnd/lists/users/archive/2007-12/message/86.

Related

Difference between com.thoughtworks.selenium and org.seleniumhq.selenium

I have got a code with following imports:
import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
I tried to use Maven to resolve, but I can't found these packages on https://mvnrepository.com. There are packages only under org.seleniumhq.selenium, but these aren't able to resolve method calls in code and there aren't any selenium named packages under com.thoughtworks.
It looks like those packages come from Selenium RC, from the times when it was created by ThoughtWorks.
See deprecated package list here, and migration guide here.
You probably want to migrate by disposing of the old dependency, re-writing the client code according to documentation, and use WebDriver.
In that case, your Maven groupID would be org.seleniumhq.selenium, as documented here.

I don't understand how to use an imported library in Java, in Netbeans

I have searched and read many similar questions here, but I could not figure it out using solutions others have posted. Hence the need to ask a new question.
I downloaded Apache Commons Math. I then installed the jar file to my libraries of the project I am working on (in Netbeans):
So in RSA.java, I would like to use the nextLong method, as seen here:
I have tried numerous import statements, such as:
import commons-math3-3.4.1.*;
or
import docs.apidocs.org.apache.commons.math3.*;
But regardless, it gives me "package does not exist" no matter what I try:
Use the javadoc to locate the correct name of the class
import org.apache.commons.math3.random.RandomDataGenerator;

Eclipse type / import error with built java file

I have a project where we use a ant buildfile to create some .java files. Those built files need to reference to already existing other java files.
My problem is that the built file can have a code line as for example
arg = (Expr) new Ast.BinaryOP(lhs, BOp.B_MINUS, rhs);
where it will show an error "Ast.BinaryOP cannot be resolved to a type". I then can type Ast.BinaryOP again and use autocomplete to pick the BinaryOP part and the error will disappear. The same with BOp.B_MINUS.
I did import (probably way too many times) the necessary other files as far as I can tell.
I.e.
import cd.ir.Ast;
import cd.ir.Ast.*;
import cd.ir.Ast.Expr;
import cd.ir.Ast.BinaryOp;
import cd.ir.Ast.BinaryOp.BOp;
So far I tried
restarting Eclipse
'clean' the project
to just run the project anyway (doesn't work)
remove the "Ast." part which will work once again if I do it in Eclipse but not if generated that way
Google the problem, respectively search it on Stackoverflow which turned out to be hard as there are many related issues. There are no good keywords as far as I can tell.
deleted the project from Eclipse and imported it newly
I need to repeatedly run the ant build file to test the code from where the .java file is generated, thus changing all errors manually is not an option.
Thanks for any advice/help in advance. I will gladly provide more information if you tell me what could help.
Hit F5 on the project, open the file, and then try hitting Ctrl+Shift+O to automatically organize the imports.
After consulting with a friend who didn't see the issue either I finally found it. So logical in retrospect but small enough that I spend 2,5h trying to find it:
import cd.ir.Ast.BinaryOp;
vs:
new Ast.BinaryOP(....
BinaryOp vs. BinaryOP

GeoGoogle(Java) - How to import the file?

I'm trying to use GeoGoogle for geocoding purposes from http://geo-google.sourceforge.net/
When I tried to use this line of code:
import geo.google.GeoAddressStandardizer;
GeoAddressStandardizer st = new GeoAddressStandardizer("AABBCC");
It says GeoAddressStandardizer and the import cannot be resolved, I also added the JAR to the build path already.
Has anyone met this issue before? Thanks
Solution: Get the geoGoogle-1.5.0.jar Instead inside https://www.cs.drexel.edu/~zl25/maven2/repo/geoGoogle/geoGoogle/1.5.0/
having a quick look through the geo-google source, this does exist as a constructor here.
public GeoAddressStandardizer(String apiKey)
So the problem has to lie in the way your application is using the jar. Are you deploying to a web server or something like that (although I'd expect a classNotFoundException)?
If you look at the build config in your IDE, does the jar exist? How did you add it?

Can't use JSONObject in Google App Engine (Java) anymore?

Half an hour ago I opened Eclipse to edit a Google App Engine app, previously everything was working fine, no errors, I haven't updated anything (at least not knowingly).
I had imported: com.google.appengine.repackaged.org.json.JSONObject
without error, however now I get this error:
use of com.google.appengine.repackaged may result in your app breaking without warning
It has never broken before, it came with the Google App Engine download for Eclipse, why has it suddenly started now? And how can I get rid of it? (they change I was making was very small and quick, it would be nice not to have to use a different JSON library)
com.google.appengine.repackaged.* contains internal classes that should not be used by application code.
org.json is implemented by many libraries, for example JSON-Java. Simply include one of them in your GAE project.
AppEngine 1.8.4 use
com.google.appengine.labs.repackaged.org.json.JSONObject
In case you don't want to have to figure this all out from first principles, here is a step-by-step:
Get the sources from https://github.com/douglascrockford/JSON-java (you can download the zip, use Git, etc.)
Make a directory in your project json/org/json and put the sources in there.
Use "Refresh" in Eclipse so that it sees and compiles the directory.
Change all the "import com.google.appengine.repackaged.org.json.xxx;" to "import org.json.xxx;" in your code
Unfortunately this adds a whole lot of Warnings, but they do seem to be harmless.
To get rid of Use of com.google.appengine.repackaged may result in your app breaking without warning. error simple declare your class with full package name. It solves your problem.
com.google.appengine.repackaged.com.google.gson.JsonObject jsonObject =
new com.google.appengine.repackaged.com.google.gson.JsonObject();
Changing my import to com.google.gson.Gson worked for me.
Package com.google.appengine.repackaged.com.google.gson has been deprecated on the latest appengine version. Therefore the following statements
import com.google.appengine.repackaged.com.google.gson.Gson;
import com.google.appengine.repackaged.com.google.gson.GsonBuilder;
...
Gson gson = new GsonBuilder().create();
will you give you the following error in your appgengine logs:
java.lang.NoClassDefFoundError: com/google/appengine/repackaged/com/google/gson/JsonElement
You need to use the new Json library instead:
1) add new dependency to your gradle file:
compile 'com.google.code.gson:gson:2.8.1'
2) replace
import com.google.appengine.repackaged.com.google.gson.Gson;
import com.google.appengine.repackaged.com.google.gson.GsonBuilder;
with
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

Categories