Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get a list of jars in a project's classPath
How to get a list of jars in a project's classPath [message #330709] Mon, 11 August 2008 11:28 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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.
>
Previous Topic:Create new project wizard
Next Topic:tabbed properties view is slow - how to improve performance ?
Goto Forum:
  


Current Time: Thu Feb 13 05:48:54 GMT 2025

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

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

Back to the top