Domino XPages Import cannot be resolved - classpath

A Domino XPages project I inherited is stating three errors:
The import com.ibm.xylem cannot be resolved
The import com.ibm.compat cannot be resolved
The import com.ibm.security cannot be resolved
I have ensured the correct XPages plugins have been installed. I have also removed the jars from the build path and re-inserted them and also cleaned the project but I still have these errors. I have also searched the internet for these jars but cannot find any.
What is going wrong with jars and project?

If you are trying to use non-standard libraries inside a Java agent, i think you have to import them in another way. When you open the agent in Domino Designer perspective, you'll see a drowdown button "Import". If you have, for example, the additional libraries as jar files, use Import > Archive.

Related

Find what plugin implements a functionality in eclipse

Most eclipse platform functionality is implemented in plugins.
I'm trying to figure out what plugin/s is/are responsible for certain functionality or actions. In my case specifically, figuring out which ones are responsible for import resolution in java files:
for the line import org.openqa.selenium.firefox.FirefoxDriver; eclipse will give me an error: the import org.openqa cannot be resolved (since I've never worked with openqa, and I haven't added it to my pom.xml file), while for the line import java.util.Iterator it just knows what we're talking about.
How can I find and dissect those behaviors, to better understand how the resolution works?
I know I can get a list of all installed plugins through: help -> about eclipse -> installation details -> plug-ins; but that isn't much help since that's just a huge list of suspects.
Conversely, I've tried running eclipse with -vm c:\jre\bin\java.exe -consoleLog to see the internal logs, but it looks like most plugins only log errors to the error log.
My guess is that using maven to enrich the project's build jars list, and some existing collection of multiple jars, eclipse will look in the project's build path to resolve the import. But that's just a guess...
Also, when the resolution fails, eclipse will give the cannot resolve import error, and allow me to figure it out through an import search window that doesn't actually find anything, which is what I'm trying to see it it's possible to improve upon.
The Maven plugin definitely plays an important role for looking up Java classes. If you right click on a project in Eclipse you should see a menu item that is called Build Path. It shows the dependencies of the project that are taken into account when Eclipse builds classes in the project. A dependency can be a jar, but it does not have to be. The dependencies include Maven dependencies.
This post is not an answer to the general question of finding a plugin that implements a functionality, but it's maybe enough for your specific case.

Getting imported files from sample java program to new program

I'm trying to make a small java program revolving around Google Calendars. I've never worked with java before but I was able to get Google's sample code working. In Eclipse, I simply used Import -> Maven, and then made some small changes to the code so that it worked on my Calendar.
Ok, great, now I want to write my own code. I started a new project and imported the Google Calendar API. At the very beginning, there are several import actions:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
.
.
.
It turns out that I'm missing the second and third files. How do I find these files and how to do import them to the new project?
Please note: I ultimately don't want to rely on importing the Google Calendar API or anything similar, as I will be using another non-java program to run and control this one.
Here's what I tried:
I go back to the sample code, expand Maven Dependencies and find:
google-oauth-client-jetty-1.19.0.jar
google-oauth-client-java6-1.19.0.jar
I see that these files are in:
C:\******\.m2\repository\com\google\oauth-client\google-oauth-client-jetty\1.19.0
C:\******\.m2\repository\com\google\oauth-client\google-oauth-client-java6\1.19.0
I tried to add these with Import -> Java EE -> App Client JAR file
Didn't work, do I need to change the file name or import name? Maybe these aren't the correct files anyway.
I also tried to add these by creating a lib folder in my project folder and add the JAR files directly there.
I guess from your question your project is just an Eclipse project rather than a Maven project. Obviously Maven automatically add the required jars of the dependencies stated in pom.xml for example google-oauth-client-java6-1.19.0.jar is a dependency of google-oauth-client-jetty-1.19.0.jar.
To add external jar to your project in Eclipse you need to select the project then from the Project menu select Properties. On the properties popup click on the Java Build Path, you have two options depending where the jars are stored, if you are referring to the maven .m2 directory then choose 'Add External Jars' otherwise if you added them to a lib folder in the project choose Add Jars

Java import directories

I want to ask smaller question about Java VM and thing about it.
If I understand import process correctly, then when I request contents of packages by import keyword in Java, packages are being imported from it's specified import directory. Then when I'm running Java application from a directory in computer and some of the imported packages could not be found in JVM import directory, JVM is looking for them in current directory. But in that case something must be wrong, because when I run my project from Eclipse and I request some package from the project, it's found. I think that Eclipse is changing directory where packages are being searched. Am I right? Is this all way of importing in Java?
The import statement is just syntactic sugar so you don't have to specify the fully qualified name everywhere in your classes. It doesn't actually import anything in terms of code.
Classes are looked up in the classpath.
In eclipse you can configure the build path (for each project) option project - - > build path.
There you can either add a directory, jar file, external jar files, etc.
Also you can check what's already defined.

Eclipse cannot find Twitter class in twitter4j

I'm using the twitter4j 2.1.11 jar, but Eclipse doesn't seem to be able to find classes within it. I added the jar as a referenced library, but get Twitter cannot be resolved to a type when trying to use it. I can add imports like import twitter4j.* but not import twitter4j.Twitter.
I can tell the class is available as it is present when I open the jar in an archive viewer. How can I get Eclipse to behave?
The problem I was having was that I was importing the wrong archive, specifically the sources archive rather than the one found in /lib of the twitter4j download.

How can I import eclipse JDT classes in a project

I want to do the following imports in a class.
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.TextEdit;
How can I import the JDT within Eclipse?
Cheers.
I think I found an easier way to do this:
right-click on your project in the Package Explorer;
choose "Build Path...";
choose "Configure Build Path";
choose the Libraries tab;
click the "Add Variable..." button;
in the list box, choose the "ECLIPSE_HOME" entry, and then click the "Extend" button;
in the list box, open up the "plugins" folder entry, scroll way down, and shift-click all the org.eclipse.jdt.* JAR files that are in the file listing beneath the folders;
click OK until you're all the way back out.
That should do it.
Unless I'm misunderstanding you, you just need to include the JDT JAR files on your classpath; they're all available in your Eclipse plugins directory. So for your project, right-click on the project's name in the Package Explorer, go to the Build Path... submenu, and choose Configure Build Path. Then in the Libraries tab, use the "Add External JARs" button to add each of the relevant JAR files from the Eclipse plugins directory.
If your'e writing plugins for Eclipse, you shouldn't really be trying to instantiate the internal packages. According to this API Rules of Engagement
Stick to officially documented APIs. Only reference packages that are documented in the published API Javadoc for the component. Never reference a package belonging to another component that has "internal" in its name---these are never API. Never reference a package for which there is no published API Javadoc---these are not API either.
For the others, add the package name to the Import-Package entry in your manifest.
There are extension points into the JDT, but if what you want to do falls outside of these, then I'm afraid you're out of luck.
If you're just looking to use a compiler in your code, without relying on the JDK (i.e. on a JRE), then I would consider shipping with a more standalone Java based Java compiler like Janino.
If you need these classes, you are probably in a plug-in project already. You should be able to import these classes by applying the quick fix "Fix project setup..." (Ctrl+1) on the line where Eclipse is complaining about the imports. That will add the required plug-ins to your MANIFEST.MF file in the META-INF directory (org.eclipse.jdt.core and org.eclipse.jface.text in your case). You can also add them manually in your MANIFEST.MF file. If your project is no plug-in project (and you have no MANIFEST.MF file) you can convert it by right-click on the project -> PDE Tools -> Convert Projects to Plug-in Project first. If you add dependencies to plug-in projects in the normal way ("configure build path") the classloading won't work properly at runtime (though it will compile).