How can I import eclipse JDT classes in a project - eclipse

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).

Related

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

Domino XPages Import cannot be resolved

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.

Maven eclipse - mutli project dependencies not appearing

I have a bunch of maven projects which all are part of a parent project. When I import the parent project into eclipse, I was expecting the child projects source folders to be listed in my parent project, however they are not. They also don't appear in the "Maven Dependencies" section.
Is this the correct behavior or am I missing something. If it is the correct behavior, then what is the best practice around doing this?
Should I be importing each project into eclipse and then editing the build path for my parent project to include them all? I really don't like this approach because I want to do everything through maven.
Note: I am not using mvn eclipse:eclipse to generate my project files, I am using the maven plugin directly in eclipse IDE as: Import existing maven projects
Thanks!
Import your parent project then close it (right click on the project in the package explorer > close project). Select it and go to file > import > maven > existing maven projets here you should see the list of the child projects, select the wanted ones then finish.
Now in your package explorer you should have :
A project parent-project where you work on the pom-parent and eventually on the src-parent
One project per child-project where you work on the corresponding pom-child and src-child
If some dependencies are missing try to update the projects (right click on the projects in the package explorer maven > update project)
Normally you don't have to edit the build path in eclipse it must be handle by the maven nature of the project (the maven nature is often represent by a M on the icons of the projects)
Normally, if you don't import "dependencies" projects, Eclipse simply uses the jars presents in your local repo (.m2).
However, I don't get what you mean by "I have a bunch of maven projects which all are part of a parent project".
Projects are not part of each other. And the child projects sources should not be listed in the sources folders. You only uses the bytecode.
If you want to "see all your sources" :
However, you can have a complete "view" of the code if you export your sources as sources jars.
If you want to be able to debug across your projects :
You then have to import all your projects in Eclipse. If a project is closed, Eclipse will use the jar like if the project was not there. If the project is open, it will use the project (not sure exactly how, but it works smoothly).

how to work with Eclipse Source Code in Eclipse itself

I have download entire Eclipse Helios/Indigo version Source Code. Now I want to work on it like some modifications and all. So I imported the entire sourceCode but now I am getting n number of errors while compiling. Moreover I am trying to RunAs> Plug-in is confusing me about the output I am getting is the changed one or what.
My Problems are-
How to import entire Eclipse SOurceCode in eclipse?
How to build the Eclipse SourceCode properly?
After modification in the SC of Eclipse , how to check the changes feasility?
I would define a target definition for your Eclipse distribution. Include all the features (including source) in the definition. Then you can use you importer to import plugins from your target definition into your workspace with sources and work from that. Having target definition is easier because you can change your setup on-demand.
Edit: Forgot to mention that in import wizard (File -> Import -> Plug-in Development -> Plug-ins and Fragments) make sure you select "Project with source folders" under "Import as". Otherwise class files will be imported as jars and not deflated into your project. Just makes it easier to work with them this way.

How to export GWT project classes into JAR file

I find it difficult to export classes from one project into JAR file, so that I could import it in another project.
How do I try?
I right-click on project in Package Explorer -> Export -> Java -> JAR file -> select all the packages I need. 'Export generated class files and resources' option is checked, other options are left unchecked. Then I click Finish.
When I import such generated .jar file into the dependent I encounter a list of errors:
The import pl.abc.xyz cannot be resolved
Xyz cannot be resolved to a type
It seems like the classes from the JAR file were not found by the compiler.
Please correct me, if I do it in a wrong way. Thanks.
It seems that you need to include in jar also java source files from the client package (sometimes also shared package depending on your GWT module structure as defined in *.gwt.xml file).
The GWT compiler requires java source for the part which has to be compiled into Java Script, to be availabe as classpath resources along with compiled classes. It is simple to achieve with ant or maven build.
You can also check Export Java source files and resources when exporting, but it will add all the source code, not only the client part.
Make sure you inherit the module in your .gwt.xml file. You want to inherit the .gwt.xml file from the GWT jar you are importing, for example:
<inherits name="com.example.youmodule.Name" />