Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find the Workspace through Java code in Eclipse

 
venki sheshgiri
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Note these apis are in the org.eclipse.core.resources and org.eclipse.core.runtime plugins.
 
venki sheshgiri
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
alejo gabriel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic