Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » programmatically setting up java projects with classpath entries coming from plugins
programmatically setting up java projects with classpath entries coming from plugins [message #194941] Fri, 04 February 2005 10:03 Go to next message
Eclipse UserFriend
Originally posted by: edoardoATenigmatecDOTnet.no.spam

How can I programmatically set up a IJavaProject whose classpath entries
include the full classpath available to some plugins ?

Elaboration:

I am writing a set of plugins that contribute a kind of project where
the user edits some type of emf model and then generates some java code
off it.
The generated java depends on some API that is included in my plugin code.
So the java project (created programmtaiclly by my wizard and by plugin
tests) must be set up so that it includes the api classes.

how do I do that

the classpath setup must be able to work both in development (eg when
these java projects are created in a runtime workbench) and in a
workbench where my plugins are properly deployed.

Edo

--
Edoardo Comar
edoardo AT enigmatec DOT net

Enigmatec Corp.
http://www.enigmatec.net
Re: programmatically setting up java projects with classpath entries coming from plugins [message #194949 is a reply to message #194941] Fri, 04 February 2005 12:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: SamMesh.gmail.com

Of course, you have a lot of choices. :)

The first one:
- make user project not Java project, but plugin project
- make it dependent on your plugin
- use *Context Menu/PDE/Update Classpath...* when necessary

--
10x,
Sam Mesh


Edoardo Comar wrote:
> How can I programmatically set up a IJavaProject whose classpath entries
> include the full classpath available to some plugins ?
>
> Elaboration:
>
> I am writing a set of plugins that contribute a kind of project where
> the user edits some type of emf model and then generates some java code
> off it.
> The generated java depends on some API that is included in my plugin code.
> So the java project (created programmtaiclly by my wizard and by plugin
> tests) must be set up so that it includes the api classes.
>
> how do I do that
>
> the classpath setup must be able to work both in development (eg when
> these java projects are created in a runtime workbench) and in a
> workbench where my plugins are properly deployed.
>
> Edo
>
Re: programmatically setting up java projects with classpath entries coming from plugins [message #195057 is a reply to message #194949] Mon, 07 February 2005 10:41 Go to previous message
Eclipse UserFriend
Originally posted by: edoardoATenigmatecDOTnet.no.spam

Thanks Sam, but I need to move on the next choice.

user project is a java (non-plugin) besides having nature 'mynature'.

The java build path needs to compile against some APIs that are included
in my plugin.

The problem is hitting me esp. for testing as when running in a runtime
workbench the following code fails,

while it works only when the code I need to reference lives in jar (like
when my plugin e.g. "org.junit' is deployed, say in jar 'junit.jar'):

IJavaProject javaProject ...
IPath path = findFileInPlugin("org.junit", "junit.jar");
if(path!=null) {
IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, null, null);
addToClasspath(javaproject,newEntry);
}

//------

public static IPath findFileInPlugin(String pluginId, String
pluginRelativeFilePath)
throws MalformedURLException, IOException {
Bundle bundle = Platform.getBundle(pluginId);
if(bundle==null) {
return null;
}
URL pluginBundleURL = bundle.getEntry("/");
URL bundleURLForfile = new URL(pluginBundleURL,
pluginRelativeFilePath);
URL localURL = Platform.asLocalURL(bundleURLForfile);

return new Path(localURL.getPath());
}


public final static void addToClasspath(IJavaProject javaProject,
IClasspathEntry newEntry) throws JavaModelException {
IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
IClasspathEntry[] newEntries = new
IClasspathEntry[oldEntries.length + 1];
System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
newEntries[oldEntries.length] = newEntry;
javaProject.setRawClasspath(newEntries, null);
}


============================================================ ==============



Sam Mesh wrote:
> Of course, you have a lot of choices. :)
>
> The first one:
> - make user project not Java project, but plugin project
> - make it dependent on your plugin
> - use *Context Menu/PDE/Update Classpath...* when necessary
>


--
Edoardo Comar
edoardo AT enigmatec DOT net

Enigmatec Corp.
http://www.enigmatec.net
Previous Topic:Doing CVS Operation Programmatically
Next Topic:Dynamic Information
Goto Forum:
  


Current Time: Fri Sep 26 11:07:14 EDT 2025

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

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

Back to the top