Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to add jar to .classpath
How to add jar to .classpath [message #289063] Thu, 28 July 2005 12:10 Go to next message
Eclipse UserFriend
Originally posted by: andreas140983.libero.it

I have create a plugin that in one of his functionality it add to the
classpath file of an existent project any library.

How to do this?
There is any method associated to the IProject that I can use?

Excuse for my English but I come from Italy!

Thanks, Andrea
Re: How to add jar to .classpath [message #289065 is a reply to message #289063] Thu, 28 July 2005 13:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: andreas140983.libero.it

Excuse I correct me, the .classpath is a file inside every javaProject!
Re: How to add jar to .classpath [message #289100 is a reply to message #289065] Fri, 29 July 2005 08:18 Go to previous messageGo to next message
Przemyslaw Doe is currently offline Przemyslaw DoeFriend
Messages: 49
Registered: July 2009
Member
I use:
IJavaProject javaProject=...;
IClasspathEntry[] entries = javaProject.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("path to
library"),null, null);
newEntries[entries.length] = newEntry;
javaProject.setRawClasspath(newEntries, null);
bye

"Andrea Sichel" <andreas140983@libero.it> schrieb im Newsbeitrag
news:68f942b9192970e6bbd11b0bf07ef060$1@www.eclipse.org...
> Excuse I correct me, the .classpath is a file inside every javaProject!
>
Re: How to add jar to .classpath [message #289106 is a reply to message #289100] Fri, 29 July 2005 10:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: andreas140983.libero.it

Excuse me but I have an error when I would use the IJavaProject.

I write this code:
IJavaProject JavaProject=
(IJavaProject)ResourcesPlugin.getWorkspace().getRoot().getPr oject( "name of
my project");

this line cause an error in my code and I don't say why!

You can help me?
Re: How to add jar to .classpath [message #289111 is a reply to message #289106] Fri, 29 July 2005 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

getProject() returns an IProject, not an IJavaProject so you are getting
a ClassCastException.

To get the IJavaProject from an IProject you would do
JavaCore.create(IProject).

Andrea Sichel wrote:
> Excuse me but I have an error when I would use the IJavaProject.
>
> I write this code:
> IJavaProject JavaProject=
> (IJavaProject)ResourcesPlugin.getWorkspace().getRoot().getPr oject( "name
> of my project");
>
> this line cause an error in my code and I don't say why!
>
> You can help me?
>

--
Thanks,
Rich Kulp
Re: How to add jar to .classpath [message #289119 is a reply to message #289111] Fri, 29 July 2005 16:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: andreas140983.libero.it

Thanks very much!!

I have resolved this problem but I have another problem:

how I can control if a library is already present before I try to insert
it?

In other words if, for example, the project created by a user has already
the library "soap.jar" and with my plugin I would to insert the same
"soap.jar", eclipse return me an error and stop the execution of my plugin.
How I can control if this library is already present?

Excuse me for my bad English but I'm Italian!

Thanks, Andrea
Re: How to add jar to .classpath [message #289121 is a reply to message #289119] Fri, 29 July 2005 16:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

You need to get the classpath entries from the IJavaProject and see if
already there.

Andrea Sichel wrote:
> Thanks very much!!
>
> I have resolved this problem but I have another problem:
>
> how I can control if a library is already present before I try to insert
> it?
>
> In other words if, for example, the project created by a user has
> already the library "soap.jar" and with my plugin I would to insert the
> same "soap.jar", eclipse return me an error and stop the execution of my
> plugin.
> How I can control if this library is already present?
>
> Excuse me for my bad English but I'm Italian!
>
> Thanks, Andrea

--
Thanks,
Rich Kulp
Re: How to add jar to .classpath [message #289142 is a reply to message #289121] Sat, 30 July 2005 13:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: andreas140983.libero.it

But I have to control the entirely path of the library that I would to
insert or only the name of the library?

In other words, if I have to insert the soap.jar and the user have already
insert it(the path is for example c:/library/soap.jar), I have to
controlonly "soap.jar" or "c:/library/soap.jar"?

Thanks, Andrea
Re: How to add jar to .classpath [message #289643 is a reply to message #289142] Tue, 09 August 2005 14:41 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

If it is an external jar, then you need to fully-qualify it, the entire
path.

So if the user already added c:/library/soap.jar then you should not add
it again.

Andrea Sichel wrote:
> But I have to control the entirely path of the library that I would to
> insert or only the name of the library?
>
> In other words, if I have to insert the soap.jar and the user have
> already insert it(the path is for example c:/library/soap.jar), I have
> to controlonly "soap.jar" or "c:/library/soap.jar"?
>
> Thanks, Andrea
>
>

--
Thanks,
Rich Kulp
Previous Topic:Load/access external icons, files and other resources
Next Topic:Annotations in external file
Goto Forum:
  


Current Time: Tue Apr 23 11:53:04 GMT 2024

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

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

Back to the top