Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Adding classpath entry to a JavaProject
Adding classpath entry to a JavaProject [message #211322] Mon, 01 August 2005 14:09 Go to next message
Eclipse UserFriend
Originally posted by: a.c.seesing.gmail.com

Hi,

I writing a plugin which shares a bit of itself with the code written inside it.
To do this, I want to make the plugin add itself to the classpath of the
JavaProject which uses it. For now I ask the user in a dialog to select the
correct *.jar file and then add that to the classpath.
But when I do that, it doesn't get added somehow, this is the code which I'm
currently using:

public void addRTInsectJAR(final IJavaProject project, final IProgressMonitor
monitor){
IPackageFragmentRoot[] roots;
try {
roots = project.getAllPackageFragmentRoots();

for (IPackageFragmentRoot root : roots) {
if(root.exists() && root.getElementName().equals(RTINSETCJAR)){
return;
}
}
// open a dialog for the user to select the rtinsect.jar
// and add it to the classpath
Display.getDefault().syncExec(new Runnable(){public void run() {
FileDialog dialog = new FileDialog(new Shell(Display.getDefault()), SWT.OPEN);
dialog.setFilterExtensions(new String[] {"*.jar"});
String result = dialog.open();
if(result == null)
return;

try {
IClasspathEntry[] entries = project.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
newEntries[0] = JavaCore.newLibraryEntry(new Path(result), null, null, true);
System.arraycopy(entries, 0, newEntries, 1, entries.length);
project.setRawClasspath(entries, monitor);
} catch (JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});

} catch (JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

If I check project.getResolvedClasspath() before and after my setRawClasspath
call, it stays the same.
My first question is: What am I doing wrong? And maybe someone can give me some
other useful tips about how to include plugin code inside a project.

Arjan Seesing
Re: Adding classpath entry to a JavaProject [message #212309 is a reply to message #211322] Fri, 12 August 2005 14:23 Go to previous message
Eclipse UserFriend
Originally posted by: noreply.gmx.de

Arjan Seesing schrieb:
> Hi,
>
> I writing a plugin which shares a bit of itself with the code written inside it.
> To do this, I want to make the plugin add itself to the classpath of the
> JavaProject which uses it. For now I ask the user in a dialog to select the
> correct *.jar file and then add that to the classpath.
> But when I do that, it doesn't get added somehow, this is the code which I'm
> currently using:
>
> public void addRTInsectJAR(final IJavaProject project, final IProgressMonitor
> monitor){
> IPackageFragmentRoot[] roots;
> try {
> roots = project.getAllPackageFragmentRoots();
>
> for (IPackageFragmentRoot root : roots) {
> if(root.exists() && root.getElementName().equals(RTINSETCJAR)){
> return;
> }
> }
> // open a dialog for the user to select the rtinsect.jar
> // and add it to the classpath
> Display.getDefault().syncExec(new Runnable(){public void run() {
> FileDialog dialog = new FileDialog(new Shell(Display.getDefault()), SWT.OPEN);
> dialog.setFilterExtensions(new String[] {"*.jar"});
> String result = dialog.open();
> if(result == null)
> return;
>
> try {
> IClasspathEntry[] entries = project.getRawClasspath();
> IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
> newEntries[0] = JavaCore.newLibraryEntry(new Path(result), null, null, true);
> System.arraycopy(entries, 0, newEntries, 1, entries.length);
> project.setRawClasspath(entries, monitor);
> } catch (JavaModelException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }});
>
> } catch (JavaModelException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> If I check project.getResolvedClasspath() before and after my setRawClasspath
> call, it stays the same.
> My first question is: What am I doing wrong? And maybe someone can give me some
> other useful tips about how to include plugin code inside a project.
>
> Arjan Seesing
>

as far as i can see, you do everything to get a new Array "newEntries"
with one more element than "entries", but then you write back "entries".

Ralf
Previous Topic:Bug in org.eclipse.jdt.internal.debug.ui.actions.ShowSystemThreadsAction?
Next Topic:automatically switch back to Java perspective when debugging is done
Goto Forum:
  


Current Time: Thu May 01 17:26:13 EDT 2025

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

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

Back to the top