Bundle bundle = Platform.getBundle(YourPlugin.getPluginId());
URL url = bundle.getEntry("/");
String targetPath = null;
try
{
targetPath = (new Path((new File(FileLocator.toFileURL(url).getPath()))
.getAbsolutePath())).toString()
}catch(Exception e)
{
e.printStackTrace();
}
------------------------------------------------------------------------
public void run(IAction action)
{
URL url = bundle.getEntry("/");
String targetPath = null;
try
{
targetPath = (new Path((new File(FileLocator.toFileURL(url).getPath()))
.getAbsolutePath())).toString()
}catch(Exception e)
{
e.printStackTrace();
}
------------------------------------------------------------------------
public void run(IAction action)
{
if (selection instanceof IStructuredSelection)
{
Object object = ((IStructuredSelection) selection).getFirstElement();
if (object instanceof ICompilationUnit)
{
ICompilationUnit iFile = (ICompilationUnit) object;
// 获得java 工程
IJavaProject jp = iFile.getJavaProject();
ipj = jp.getProject();
String jpName = jp.getElementName();
// 获得.java文件名
String claName = iFile.getElementName();
// 取得所选文件的包名
String path = iFile.getParent().getElementName();
}
}
}
{
Object object = ((IStructuredSelection) selection).getFirstElement();
if (object instanceof ICompilationUnit)
{
ICompilationUnit iFile = (ICompilationUnit) object;
// 获得java 工程
IJavaProject jp = iFile.getJavaProject();
ipj = jp.getProject();
String jpName = jp.getElementName();
// 获得.java文件名
String claName = iFile.getElementName();
// 取得所选文件的包名
String path = iFile.getParent().getElementName();
}
}
}