Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Locating another project
Locating another project [message #522535] Mon, 22 March 2010 18:34 Go to next message
Eclipse UserFriend
I've got several projects in my workspace in Eclipse 3.4.2. With my RCP code in project 1 I want to write some files into folders in project 2.

I cannot get a good resource for the second project.

My code is:
String outputProjectName = "/com.qualityeclipse.favorites";
IWorkspaceRoot wr =
ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = wr.getProjects();
System.out.println( "number of projects in workspace: "
+ projects.length );
for ( IProject proj : projects ) {
System.out.println( "a project is " + proj.getName() );
}
It always shows no projects in the workspace, even though Eclipse shows 15 projects in the workspace.

A (probably related) strangeness is that the WorkspaceRoot's getLocationURI() method returns a value
C:\runtime-EclipseApplication where there are no projects, instead of the location of the workspace which is
C:\EclipseTest\... where the 15 projects are located.

Thanks.

Dave Patterson
Re: Locating another project [message #522539 is a reply to message #522535] Mon, 22 March 2010 14:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NOSPAM.ibm.com

When you kick off an Eclipse RCP application from an Eclipse development
workspace you are NOT running against your development Eclipse
workspace. You are running against a DIFFERENT workspace with a
DIFFERENT java instance. This java instance will have your target
plugins PLUS your plugin projects from your development workspace. So it
will have a different workspace because you can't have two Eclipse
instance working on the same workspace.


--
Thanks,
Rich Kulp
Re: Locating another project [message #522540 is a reply to message #522535] Mon, 22 March 2010 14:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NOSPAM.ibm.com

When you kick off an Eclipse RCP application from an Eclipse development
workspace you are NOT running against your development Eclipse
workspace. You are running against a DIFFERENT workspace with a
DIFFERENT java instance. This java instance will have your target
plugins PLUS your plugin projects from your development workspace. So it
will have a different workspace because you can't have two Eclipse
instance working on the same workspace.

Some additional info:

See

http://www.eclipse.org/articles/Article-Your%20First%20Plug- in/YourFirstPlugin.html

and

http://www.eclipse.org/articles/Article-PDE-does-plugins/PDE -intro.html

They are a little old but the basic concepts are still valid.

--
Thanks,
Rich Kulp
Re: Locating another project [message #522551 is a reply to message #522540] Mon, 22 March 2010 23:09 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the info.

A great big AHA! accompanied with a smack to my head.

Dave P
Re: Locating another project [message #522783 is a reply to message #522540] Tue, 23 March 2010 18:02 Go to previous messageGo to next message
Eclipse UserFriend
Rich,

Thanks for the info.

I've now added the right project to the Project Explorer for my execution environment and can locate a file in that area. The project I want to use for output is an SVN project, so I can update the files and then check them in from the execution environment and they show up (after a refresh) in the development environment.

An additional question. The data I want to put into a file is in my program as a String. Is there a recommended way to dump a String into a file?

What I have done is:
Path newFilePath = new Path( newFileName + ".java" );
IFile outFile = myPackage.getFile( newFilePath );
if ( outFile.exists() ) {
outFile.delete( true, new NullProgressMonitor() );
}
outFile.create( new StringBufferInputStream( newContents ),
IResource.FORCE,
new NullProgressMonitor() );

This gets complaints from the compiler because the StringBufferInputStream is deprecated. While the StringReader is what is recommended, I don't see how to get an InputStream from it.

Another approach I've considered (but have not been looking forward to implementing) would be to invoke a blank editor session, set my String contents into a Document, set that into the editor and then do a save.

When I run it in debug mode, it works fine, but there are some probems I see when I run it at full speed. It seems to hang up in the middle of an operation where I need to create 8-10 files in rapid succession.

Any help would be appreciated.

Dave Patterson
Re: Locating another project [message #523005 is a reply to message #522783] Wed, 24 March 2010 14:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NOSPAM.ibm.com

Hi,

I don't know why they don't provide one, but you will need to do the
following. The disadvantage of this is that data will be duplicated into
memory, one the string and two the byte array representation.

String yourdata = ...
InputString is = new ByteArrayInputString(yourdata.getBytes("yourcharset"));

"yourcharset" is the character set that you want the data to be written,
such as "UTF-8".


--
Thanks,
Rich Kulp
Re: Locating another project [message #523075 is a reply to message #523005] Wed, 24 March 2010 20:03 Go to previous message
Eclipse UserFriend
Thanks for the clue.

Dave P
Previous Topic:Introduce Indirection does nothing on a .class file
Next Topic:Embed Text Editor in a Windows Application
Goto Forum:
  


Current Time: Tue Apr 15 01:00:03 EDT 2025

Powered by FUDForum. Page generated in 1.05217 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top