DZone Forums
Go Back   DZone Forums > Community > Tools & IDEs > Eclipse
Reload this Page How to access a file in a project of running instance from a plug-in
Notices
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 17
Thanks: 2
Thanked 0 Times in 0 Posts
Join Date: Apr 2010
Cool How to access a file in a project of running instance from a plug-in - 04-17-2010, 08:00 PM

I need help!
I have written a view based plugin that needs to access a file from a target java project. Accessing the file not at the plugin development time, but after the plugin is deployed and running with a java project in Eclipse.
I have a class View that extends ViewPart. Is there any way to accomplish using getViewSite()? Or some other way?

Thanks.

cool.msg@hotmaii.com
Reply With Quote
  (#2 (permalink)) Old
Active Contributor
 
Posts: 45
Thanks: 0
Thanked 4 Times in 4 Posts
Join Date: Oct 2009
Post 04-19-2010, 08:38 AM

If I understand you correctly, you would use various IContainer interfaces (IProject, IFolder, IFile) to get the information you want from the Java project.

You get these containers through the ResourcesPlugin. The methods needed are getWorkspace(), getRoot(), and possibly getLocation() or getProject(). getWorkspace() is a ResourcesPlugin method. getRoot() is an IWorkspace method, and getLocation() is an IResource method. getProject() is an IWorkspaceRoot method.
Reply With Quote
The Following User Says Thank You to ggleblanc For This Useful Post:
timkebox (04-19-2010)
  (#3 (permalink)) Old
Member
 
Posts: 17
Thanks: 2
Thanked 0 Times in 0 Posts
Join Date: Apr 2010
Thumbs up 04-19-2010, 08:16 PM

Thank for your answer.

I have two questions for you if you don't mind to answer.
1. ResourcesPlugin seems to work in the plugin development time. But after exporting and installing the plugin in dropin directory of MyEclipse, I am getting the following error:
java.lang.ClassNotFoundException: org.eclipse.core.resources.ResourcesPlugin

Initially org.eclipse.core.resources was missing. So I added it as Imported Packages under Dependencies. I cannot figure out how to resolve it. I tried to copy the jar file to plugin directory, but it didn't help.

2. Is there a method that takes a filename and returns absolute path?

Thanks.
Reply With Quote
  (#4 (permalink)) Old
Active Contributor
 
Posts: 45
Thanks: 0
Thanked 4 Times in 4 Posts
Join Date: Oct 2009
Smile 04-20-2010, 07:24 AM

I'm assuming you're writing your plug-in using Eclipse 3.5 Galileo. If not, let me know which version of Eclipse you're using. Plug-ins can be version specific, depending on what you're doing.

1. org.eclipse.core.resources is a required plug-in, not an imported package. You'll also probably need org.eclipse.core.runtime

2. It's going to take more than just one method call, but the method getFullPath() of the IFile interface will return an IPath. The IPath gives you the path up to the project name. Here's an example of an IPath: /gov.bop.test/src/gov/bop/test/Activator.java

To get the rest of the path, you need the workspace IPath, which you get with the following method call: Platform.getLocation();

You concatenate the two IPaths with the append() method to get the full IPath to your file.

I realize that the Eclipse Javadoc is daunting when you're beginning, but you need to start working with it. You can get there by Help -> Help Contents. Open up the Platform Plug-in Developer Guide, and click to Reference -> API Reference.

I hope this is helpful.
Reply With Quote
The Following User Says Thank You to ggleblanc For This Useful Post:
timkebox (04-20-2010)
  (#5 (permalink)) Old
Member
 
Posts: 17
Thanks: 2
Thanked 0 Times in 0 Posts
Join Date: Apr 2010
Thumbs up 04-20-2010, 09:46 AM

Actually I had tried as a required package, and got the same error. Still cannot figure out why. I am not sure if it happens because I am using Eclipse IDE for Java EE Developers (190 MB) rather than Eclipse IDE for Java Developers(92 MB). I assumed that Java EE version includes the version of Java Developer when I downloaded Eclipse a few days ago.

However, based on your reply, I was digging methods and finally got this, which I wanted:

Platform.getInstanceLocation().getURL().getPath()

This returns the root path of workspace, which I pass as a value to -data option when I launch MyEclipse.

Thanks again for your help.
Reply With Quote
  (#6 (permalink)) Old
Active Contributor
 
Posts: 45
Thanks: 0
Thanked 4 Times in 4 Posts
Join Date: Oct 2009
Wink 04-20-2010, 10:19 AM

The Eclipse IDE for Java EE Developers doesn't include the Eclipse source code and some developer tools. The Eclipse for RCP/Plug-in Developers is the Eclipse you want.

You can unzip the RCP Eclipse over the EE Eclipse, and get both sets of tools. I won't guarantee that Eclipse will work perfectly after the overlay, but I've done it before.
Reply With Quote
Reply

Tags
java model, plugin

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
No output in console while running ant build file in Eclipse bibhash.roy@gmail.com Eclipse 7 01-24-2011 06:40 AM
running crystal reports renjini Eclipse 6 12-13-2010 06:41 AM
How to set up my eclipse project to build a jar file from two jar files powah Java 0 11-13-2008 02:55 PM
Jar file in Dynamic Web Project boyrobot Eclipse 0 04-17-2008 09:26 AM
Access Local File System jayjamba Eclipse 9 04-09-2008 02:23 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com