Open java source in Eclipse based on project path - eclipse

I want to open a java source in Eclipse where the code is already in an Eclipse Project.
I tried to achieve this with Eclipse: How to open an editor programatically, but therefore you need an IPath and this IPath is only available when you build a plugIn. So I was wondering on how to implement this without a plugIn. Basically, I wanna have a class with a method which will open the java source in Eclipse based on a parameter that value is the project path, i.e. "com.MyProject.HelloWorld".

Related

Eclipse Plugin for reading Java code of current project

I want to make an eclipse plugin which can analyze java code in the current project and display it in the editor.
Scenario:
On right-clicking the java file inside eclipse, I want my plugin option to be seen (which is successfully done) and on clicking it, an editor should open with the contents of that particular java file.
I am stuck at opening the java file and reading its contents.
I think the org.eclipse.jface.text can be of help.
For editor support, I am using org.eclipse.ui.editors.
How to proceed with reading the contents of particular java file that has been right clicked ?
I am new to eclipse plugin development.
Any help is highly appreciated.
I solved the problem even better way than expected.
In the handler class's execute method , I used IWorkspace and IWorkspaceRoot from org.eclipse.core.resources package.
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
From above code, I had access to each and every resource of the current workspace. I fetched the project using IJavaProject and filtered java files from the resources.

java API source files in eclipse

In some eclipse installations I have noted that they are able to view all the source files inside a jar(may be if the jar has source files packaged in it or another jar for source?).
If we ctrl+click or f3 on a class type, then it shows the source code of the JAVA API for that class. Likewise for many classes. even for some third party classes like apache's. But in my installation i just get a white screen with the name of the jar and some mess of unreadable content. And also previously I have got javadocs of JAVA API very well before when i hover my mouse over the class or function names. But in my current installation even that is gone.
How to get java docs and source file viewing in eclipse? i am using eclipse juno... downloaded within 6months..
Make sure that Eclipse is using a full JDK rather than just a JRE. Look in Preferences / Java / Installed JREs to see what Eclipse is using.

How to add eclipse-source javadoc to java-build-path in?

I have an Eclipse RCP Project.
I am using Eclipse source classes, for that I am have a target platform with Eclipse's update site.
The plugins are imported from the target site, but without the Javadoc.
Quesion:
What is the location of the Eclipse's Javadoc for Eclipse RCP classes?
Add the Javadoc for a jar
It is also possible to add Javadoc to a library which you use.
Download the Javadoc of the jar and put it somewhere in your filesystem.
Open the Java Build Path page of a project via Right click on a project → Properties → Java Build Path. On the Libraries tab expand the library's node, select the Javadoc location attribute and press the Edit button.
Enter the location to the file which contains the Javadoc.
sourcepath="D:/eclipse3.3.2/plugins/org.eclipse.rcp.source_3.3.3.r33x_r20080129-8y8eE9UEUWI6qujeED0xT7bc/src/org.eclipse.osgi_3.3.2.R33x_v20080105/src.zip"
just try to adapte this to your case.
There is a checkbox to import the sources, inside of teh target platform's update-site dialog.

Eclipse Open Declaration does not work for Ant project

My eclipse is Indigo version. Open declaration works in creating new java projects in my elipse.
But in the case, I get alfresco source code of the whole project(assumed as root) from the svn and root is composed of many java projects. It is built with ant i.e. by running build.xml to build jar from each java project and finally create a war file and deploy.
In this project, open declaration F3 and open type Hierarchy F4 does not work.
It is said
The resource is not on the build path of a Java Project.
So I take another workspae and import these java projects inside root one after another. Open declaration F3 and open type Hierarchy F4 works. But this workspace is just to see source file and does not work.
I want to know what is the reason of F3 and F4 does not work and can you explain how to fix it?
You need to add the JAR files to the build path of your project and then attach source to them.
Right click on your project in the Package Explorer or Navigator and select the Java Build Path:
Click on 'Add External JARs...' to add JAR files. The answers to this question provide info on how to attach source to the JARs.

How do I attach source code locations to plugins in my Eclipse RCP target platform?

I've got a workspace with multiple RCP plugin projects.
We've set the target platform, so we can build against a standard set of plugins, but are not able to see source code and Javadoc for all the platform plugins.
The Windows -> Preferences -> Plug-in Development -> Target Platform -> Source Code Locations page doesn't seem to have any effect when I add the eclipse directory (it only allows you to add directories).
Copying the source jars from the eclipse directory into the target platform has a similar effect.
What am I doing wrong? How do I attach a set of Source jars to my target platform?
I had the same problem today. In my case I wanted to debug into the source of the plugin embedded jetty (org.mortbay.jetty_5.1.14.v200806031611.jar) which comes with Eclipse Equinox (OSGI) which is part of my eclipse target platform.
When debugged and wanted to go into any class inside a jetty package I always got the message that it is a class from Plugin-Dependencies and the source attachment cannot be modified.
I solved it like this:
Switch to the Plugins View in Eclipse ( Window / Show View / Plugins)
locate the bundle org.mortbay.jetty
right click on that bundle and select "Import as" -> "Binary Project with linked content"
Now that Bundle shows up in your Package Explorer as a new Eclipse project, in my case org.mortbay.jetty.
Now right click on that new project in the package explorer and goto 'Properties / Java Build Path / Libraries'. You see the the jetty jar file there and if you expand this entry you can edit the 'Source Attachment' as usual. I pointed it to the downloaded Jetty Source code located in a completely different folder than my target platform which I am using for my project.
If you use Eclipse SDK bundles when building your target platform, you should be immediately provided with "Java Source Attachment" and "Javadoc Location" for each Eclipse plugin.
For example, I used "Eclipse Platform SDK" (eclipse-platform-SDK-3.4.2-win32) as target space and when I display the "Source Code Locations page" that you mentionned, it is filled with "Source locations declared in the target platform". In the Eclise IDE, I can then see Eclipse core plugins source code and javadoc (in JFace packages for example).
Otherway, it is not so easy to add plugins source code locations but you can succeed it in 2 ways :
providing a "source plugin" (the easiest way if the plugin provider also supplies the source plugin) into the target platform, as an ordinary plugin (PDE will recognise it)
providing an additional source location (not the easy way ...)
You can find more information about Target Source Code Locations in you Eclipse Help, in the following topic :
Plug-in Development Environment Guide > Tools > Preferences > Target Platform Preferences > Source Code Locations
All sources are available if you download the 'Eclipse for RCP and RAP Developers' build from the main downloads page. At least, that's what it's called for the Juno build, it used to be called Eclipse for RCP/Plug-in Developers.
It doesn't look like the plugin source code is available via the standard Java/J2ee Eclipse builds any longer. I was assuming the sources would be available via the update mechanism but have been unable to find the correct update site/feature. If anyone knows, please comment.
I can modify the target platform at runtime, using the -install runtime option. Keep the targetPlatform as the eclipse platform.
However, this loses a lot of the benefits of using a target platform in the first place - i.e. compile time safety.