How to get a list of jars in a project's classPath [message #330709] |
Mon, 11 August 2008 11:28  |
Eclipse User |
|
|
|
We are developing an eclipse plug-in.
We want to know the list of jars on the classPath of the selected project.
We have the IProject object of the selected project.
How do we get the full paths of jars on the classPath of the project?
Thanks in advance.
|
|
|
Re: How to get a list of jars in a project's classPath [message #330710 is a reply to message #330709] |
Mon, 11 August 2008 11:34   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------060907080705040905070303
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Prasanna,
Here's a snip of code that should help you get started:
IJavaProject javaProject = JavaCore.create(project);
urls.add(new File(project.getLocation() + "/" +
javaProject.getOutputLocation().removeFirstSegments(1) + "/").toURL());
// Compute the URLs for all the output folder of all
the project dependencies.
//
for (IClasspathEntry classpathEntry :
javaProject.getResolvedClasspath(true))
{
if (classpathEntry.getEntryKind() ==
IClasspathEntry.CPE_PROJECT)
{
IPath projectPath = classpathEntry.getPath();
IProject otherProject =
workspace.getRoot().getProject(projectPath.segment(0));
IJavaProject otherJavaProject =
JavaCore.create(otherProject);
urls.add(new File(otherProject.getLocation() +
"/" + otherJavaProject.getOutputLocation().removeFirstSegments(1) +
"/").toURL());
}
}
The idea is you need to get at the IJavaProject and analyze the class
path for that.
Prasanna wrote:
> We are developing an eclipse plug-in.
> We want to know the list of jars on the classPath of the selected
> project.
> We have the IProject object of the selected project.
> How do we get the full paths of jars on the classPath of the project?
> Thanks in advance.
>
--------------060907080705040905070303
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Prasanna,<br>
<br>
Here's a snip of code that should help you get started:<br>
<blockquote><small>
|
|
|
Re: How to get a list of jars in a project's classPath [message #330723 is a reply to message #330710] |
Tue, 12 August 2008 05:28   |
Eclipse User |
|
|
|
Hi Ed,
Thanks for your reply.
After going through the code snippet you had posted, I checked out the
javadoc for IClasspathEntry.
This is how I got full paths (on file system) of all the jars on the
classPath of the selected project :
List<String> classPathEntriesList = new ArrayList<String>();
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
for(IClasspathEntry classPathEntry : classPathEntries) {
if( classPathEntry.getContentKind() ==
IPackageFragmentRoot.K_BINARY)
classPathEntriesList.add(classPathEntry.getPath().toString() );
}
for(ListIterator<String> it = classPathEntriesList.listIterator();
it.hasNext();) {
classPath += it.next();
if(it.hasNext())
classPath += ";";
}
This link helped me :
http://dev.eclipse.org/newslists/news.eclipse.platform/msg69 997.html
I'd like to know What do I stand to loose if I don't follow the road-map
shown by you.
Thanks.
|
|
|
Re: How to get a list of jars in a project's classPath [message #330731 is a reply to message #330723] |
Tue, 12 August 2008 11:48  |
Eclipse User |
|
|
|
Prasanna,
I'm not an expert on this by any means. I just snipped some code from
one of the classes I on in the past to help get you started. It's been
a while since I looked at code for this...
Prasanna wrote:
> Hi Ed,
> Thanks for your reply.
> After going through the code snippet you had posted, I checked out the
> javadoc for IClasspathEntry.
> This is how I got full paths (on file system) of all the jars on the
> classPath of the selected project :
>
> List<String> classPathEntriesList = new ArrayList<String>();
> IJavaProject javaProject = JavaCore.create(project);
> IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
> for(IClasspathEntry classPathEntry : classPathEntries) {
> if( classPathEntry.getContentKind() ==
> IPackageFragmentRoot.K_BINARY)
> classPathEntriesList.add(classPathEntry.getPath().toString() );
> }
> for(ListIterator<String> it = classPathEntriesList.listIterator();
> it.hasNext();) {
> classPath += it.next();
> if(it.hasNext())
> classPath += ";";
> }
>
> This link helped me :
> http://dev.eclipse.org/newslists/news.eclipse.platform/msg69 997.html
>
> I'd like to know What do I stand to loose if I don't follow the
> road-map shown by you.
>
> Thanks.
>
|
|
|
Powered by
FUDForum. Page generated in 0.03244 seconds