IClasspathContainer for lib directory [message #22034] |
Tue, 13 May 2003 23:12 |
Joss Wright Messages: 32 Registered: July 2009 |
Member |
|
|
I am trying to create a container for the lib directory of a Java project,
specifically for a WebApp project. When I create my project I call the
following:
// WEB-INF/lib/*.jar files
entries.add(JavaCore.newContainerEntry(new Path("WEB-INF/lib"), false));
JavaCore
.setClasspathContainer(
new Path("WEB-INF/lib"),
new IJavaProject[] { this.getJavaProject()},
// value for 'myProject'
new IClasspathContainer[] {
new IClasspathContainer() {
public IClasspathEntry[] getClasspathEntries() {
Vector entries = new Vector();
IResourceChangeListener listener =
new IResourceChangeListener() {
public void resourceChanged(
IResourceChangeEvent event) {if (
event.getDelta().findMember(
libFolder.getFullPath())
!= null) {
System.out.println("lib changed!!");
}
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(
listener,
IResourceChangeEvent.POST_CHANGE);
try {
IResource[] lib = libFolder.members();
for (int i = 0; i < lib.length; i++) {
if (("jar").equalsIgnoreCase(lib[i].getFileExtension())) { //$NON-NLS-1$
entries.add(
JavaCore.newLibraryEntry(
lib[i].getFullPath(),
null,
null));
}
}
} catch (CoreException e) {
}
return (IClasspathEntry[]) entries.toArray(
new IClasspathEntry[entries.size()]);
}
public String getDescription() {
return "WEB-INF Library";
}
public int getKind() {
return IClasspathContainer.K_APPLICATION;
}
public IPath getPath() {
return new Path("WEB-INF/lib");
}
}
}, null);
To add the container to my classpath entries, however I'm not sure if
using a IResourceChangeListener in this manner is correct. It seems to
fire a number of times for a single change event on the lib folder.
Furthermore I'd anticpated creating a ClasspathContainerInitializer class
and calling the requestClasspathContainerUpdate() from within the
resourceChanged() method.
Finally is it possible for a IClasspathContainer to reference a classpath
variable that points to a lib folder, so that any Java project could
simply have a lib folder that is a classpath container if the folder is
referenced by that variable.
I hope I have made sense.
Regards,
Joss
|
|
|
Re: IClasspathContainer for lib directory [message #28967 is a reply to message #22034] |
Mon, 19 May 2003 09:18 |
Philippe Mulet Messages: 229 Registered: July 2009 |
Senior Member |
|
|
Why are you defining a resource change listener at all ? Are you trying to
collect all the JARs from the lib folder, if so a resource visitor is all
you would need to do, but only once (when the container is created). I could
imagine that using a resource change listener you may want to decide to
update your container down the road, but this shouldn't be added inside the
#getClasspathEntries method itself, which can be invoked quite often
whenever the container is consulted.
As for #requestClasspathContainerUpdate(...), it is meant for multiple code
parties to interact on container values. Currently, it is used for
indicating to the JRE container owner (launch plugin) that some update is
requested by the UI client (through user input in container wizard).
Did you consider registering a container initializer to better get lazily
activated when the container need to be resolved ?
"Joss Wright" <joss.wright@talk21.com> wrote in message
news:b9ru5b$q2e$1@rogue.oti.com...
> I am trying to create a container for the lib directory of a Java project,
> specifically for a WebApp project. When I create my project I call the
> following:
>
> // WEB-INF/lib/*.jar files
> entries.add(JavaCore.newContainerEntry(new Path("WEB-INF/lib"), false));
>
> JavaCore
> .setClasspathContainer(
> new Path("WEB-INF/lib"),
> new IJavaProject[] { this.getJavaProject()},
> // value for 'myProject'
> new IClasspathContainer[] {
> new IClasspathContainer() {
> public IClasspathEntry[] getClasspathEntries() {
> Vector entries = new Vector();
> IResourceChangeListener listener =
> new IResourceChangeListener() {
> public void resourceChanged(
> IResourceChangeEvent event) {if (
> event.getDelta().findMember(
> libFolder.getFullPath())
> != null) {
> System.out.println("lib changed!!");
> }
> }
> };
> ResourcesPlugin.getWorkspace().addResourceChangeListener(
> listener,
> IResourceChangeEvent.POST_CHANGE);
> try {
> IResource[] lib = libFolder.members();
> for (int i = 0; i < lib.length; i++) {
> if (("jar").equalsIgnoreCase(lib[i].getFileExtension())) { //$NON-NLS-1$
> entries.add(
> JavaCore.newLibraryEntry(
> lib[i].getFullPath(),
> null,
> null));
> }
> }
> } catch (CoreException e) {
> }
> return (IClasspathEntry[]) entries.toArray(
> new IClasspathEntry[entries.size()]);
> }
> public String getDescription() {
> return "WEB-INF Library";
> }
> public int getKind() {
> return IClasspathContainer.K_APPLICATION;
> }
> public IPath getPath() {
> return new Path("WEB-INF/lib");
> }
> }
> }, null);
>
> To add the container to my classpath entries, however I'm not sure if
> using a IResourceChangeListener in this manner is correct. It seems to
> fire a number of times for a single change event on the lib folder.
>
> Furthermore I'd anticpated creating a ClasspathContainerInitializer class
> and calling the requestClasspathContainerUpdate() from within the
> resourceChanged() method.
>
> Finally is it possible for a IClasspathContainer to reference a classpath
> variable that points to a lib folder, so that any Java project could
> simply have a lib folder that is a classpath container if the folder is
> referenced by that variable.
>
> I hope I have made sense.
>
> Regards,
>
> Joss
>
|
|
|
Powered by
FUDForum. Page generated in 0.03823 seconds