how to work with Eclipse Source Code in Eclipse itself - eclipse

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.

Related

How to import Eclipse user libraries into IntelliJ Idea

I have lib.userlibraries file with the following content:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<eclipse-userlibraries version="2">
<library name="MyLib" systemlibrary="false">
<archive path=PATH_TO_LOCAL_JAR_1/>
<archive path=PATH_TO_LOCAL_JAR_2/>
...
<archive path=PATH_TO_LOCAL_JAR_100/>
</library>
</eclipse-userlibraries>
I want to import these local jar files to the project in IntelliJ Idea. I can do it manually via File -> Project Structure... -> Libraries, but it will require to import each jar file separately. Is there automatic way to import this userlibraries file to IntelliJ Idea project?
The other answer about using the IntelliJ import feature for eclipse projects should be your first "stop".
Beyond that: importing doesn't necessarily work for all projects. We have a large, complicated eclipse project. Trying to import that in IntelliJ simply didn't work (the module definition that IntelliJ created was completely wrong, and lead to thousands and thousands of build errors).
In that specific case, it might be faster to use a powerful text editor, like:
open the eclipse .classpath file
create a new IntelliJ project, and import maybe one of the required libraries manually
open the corresponding module xyz.iml file
simply compare/copy ( get the JAR file names from eclipse, and use editor magic to create the raw strings you need for the .iml file )
Of course, that seems silly, but as said: using a text editor, I got a large setup with 15 modules/projects to build fine in less than an hour.
And the real answer: base your project setup on a tool like maven or gradle. Because these tools allow you to generate eclipse or IntelliJ configuration files. If possible, always do that. Even when it means to learn a new tool, and a lengthy transition period.
In IntelliJ IDEA open the Eclipse project by importing from Eclipse wizard. It will give you an opportunity to select user libraries.

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.

Diffrence between importing an existing project into Eclipse VS adding a dependency

I need you help understanding nub stuff
What is the Difference between
1. Importing and existing project into Eclipse
2. Adding a dependency ?
The "difference" is that those two are completely different things.
If you import projects into the workspace, you can edit them. For example, you could create a project with Maven, generate Eclipse project files and then import it into Eclipse, or checkout an existing project from SVN or Git am import that one. You can not edit individual files in Eclipse; everything has to be part of a project.
If you add a dependency, you can use the things defined in that dependency in another project. Usually, that dependency would be a JAR file. You can add individual JAR files manually, or use other Programs like Maven aggregate the dependencies and add them to the project.
Also, you can add a project from the workspace as a dependency to another project (after importing both into the workspace). Compared to adding a JAR file as a dependency, this has the advantage that you can edit the one project and the changes will imediately be reflected in the second project that depends on the first one. This makes development much easier than generating a new JAR file from that project every time something changes.

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

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