aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to find the Workspace through Java code in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to find the Workspace through Java code in Eclipse" Watch "How to find the Workspace through Java code in Eclipse" New topic
Author

How to find the Workspace through Java code in Eclipse

venki sheshgiri
Greenhorn

Joined: Jan 01, 2006
Posts: 28
We have a requirement where we need a reference to the Workspace Directory to carry out certain operations.is there any API in eclipse which can do it ?
Roy Paterson
Smart Bear Support
Greenhorn

Joined: Jul 07, 2009
Posts: 6


Note these apis are in the org.eclipse.core.resources and org.eclipse.core.runtime plugins.


Smart Bear
venki sheshgiri
Greenhorn

Joined: Jan 01, 2006
Posts: 28
Hi Roy thanks for the code snippet, I also need to find from which path the Eclipse was launched(the dir where eclipse.exe resides) any Info on this would also be very usefull to me Thanks again.
Roy Paterson
Smart Bear Support
Greenhorn

Joined: Jul 07, 2009
Posts: 6
I'm less sure about this one but it seems to work in Eclipse 3.5:



I suggest you test this in all the versions of Eclipse you're trying to support before relying on it.

Roy
Lars Vogel
Ranch Hand

Joined: Oct 10, 2007
Posts: 55
Hello,

Eclipse JDT is what you are looking for to access your workspace. An example which reads your workspace projects and evaluates certain measurements can be found here:

Eclipse JDT Tutorial

Best regards, Lars

Tutorials about Java, Eclipse and Webprogramming http://www.vogella.de
alejo gabriel
Greenhorn

Joined: Jul 17, 2009
Posts: 1
Hello:

I use WID 6.1.2 Build id: 6.1.2ifix004-20090401_1943.
When I do

IWorkspace workspace = ResourcesPlugin.getWorkspace();
String folder= workspace.getRoot().getLocation().toFile().getPath().toString();
System.out.println("Folder: " + folder);

The result is "C:\WID612\pf\wps", the folder where I install the WID

How I get the name of the workspace folder with code java, for example "C:\myWorkspace\myProyect".?

What I really need is to open the file new.properties in the folder "C:\myWorkspace\myProyect\Resources".

String locationFile = ???

FileInputStream propertiesFile = new FileInputStream(locationFile);
properties.load(propertiesFile);
String user = properties.getProperty("dataSource.username");

Any idea?

Thanks
Kevin Kucera
Greenhorn

Joined: Apr 09, 2013
Posts: 1
Using Eclipse Juno for Java.

I have the same question. The path I'm looking for is the path that Eclipse requests in the Workspace Laucher pop up window. Something like:

C:\Project_Files\workspace

All the previous code snippets give me is this:

C:\Project_Files\runtime-msa.application.product

which is useless for my purposes.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to find the Workspace through Java code in Eclipse