claspath relative to plugin [message #263334] |
Mon, 18 August 2008 06:10  |
Eclipse User |
|
|
|
Originally posted by: agata.vackova.javlinconsulting.cz
Hi,
is is possible to set classpath in project properties relative to an
plugin? I need to set something like that:
<classpathentry kind="lib"
path=" platform:/plugin/com.cloveretl.gui/lib/lib/cloveretl.engine. jar "/>
So, the path would depend on the plugin location and in different eclipses
the path would show to different locations.
|
|
|
|
|
|
|
Re: claspath relative to plugin [message #263352 is a reply to message #263345] |
Mon, 18 August 2008 07:15   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------010104060708010604030004
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Agad,
We have some somewhat brutal code like this that determines the
classpath for plugins and creates variables to put on the classpath of a
generated project, but we generally avoid that now by always creating a
project with a PDE nature:
| *public static *List<String> getClasspathPaths(String pluginID) *throws *JETException
{
List<String> result = *new *ArrayList<String>();
*try*
{
Bundle bundle = Platform.getBundle(pluginID);
String requires = (String)bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH);
*if *(requires == *null*)
{
requires = ".";
}
ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, requires);
*if *(elements != *null*)
{
*for *(*int *i = 0; i < elements.length; ++i)
{
ManifestElement element = elements[i];
String value = element.getValue();
*if *(".".equals(value))
{
value = "/";
}
*try*
{
URL url = bundle.getEntry(value);
*if *(url != *null*)
{
URL resolvedURL = FileLocator.resolve(url);
String resolvedURLString = resolvedURL.toString();
*if *(resolvedURLString.endsWith("!/"))
{
resolvedURLString = resolvedURL.getFile();
resolvedURLString = resolvedURLString.substring(0,resolvedURLString.length() - "!/".length());
}
*if *(resolvedURLString.startsWith("file:"))
{
result.add(resolvedURLString.substring("file:".length()));
}
*else*
{
result.add(FileLocator.toFileURL(url).getFile());
}
}
}
*catch *(IOException exception)
{
*throw new *JETException(exception);
}
}
}
}
*catch *(BundleException exception)
{
*throw new *JETException(exception);
}
*return *result;
}
/**
* An {@link IClasspathAttribute#getName() class path attribute name}
* that records the originating plugin ID
* for each classpath entry created by
* {@link #addClasspathEntries(Collection, String)}
* and {@link #addClasspathEntries(Collection, String, String)}.
* @since 2.3
*/
*public static final *String PLUGIN_ID_CLASSPATH_ATTRIBUTE_NAME = "plugin_id";
*public static **void *addClasspathEntries(Collection<IClasspathEntry> classpathEntries, String variableName, String pluginID) *throws *JETException
{
*for *(ListIterator<String> i = getClasspathPaths(pluginID).listIterator(); i.hasNext(); )
{
IPath path = *new *Path(i.next());
*if *(variableName == *null*)
{
classpathEntries.add
(JavaCore.newLibraryEntry
(path, null, null, null, *new *IClasspathAttribute [] { JavaCore.newClasspathAttribute(PLUGIN_ID_CLASSPATH_ATTRIBUTE _NAME, pluginID) } , *true*));
}
*else*
{
String mangledName = variableName + (i.previousIndex() == 0 ? "" : "_" + i.previousIndex());
*try*
{
JavaCore.setClasspathVariable(mangledName, path, *null*);
}
*catch *(JavaModelException exception)
{
*throw new *JETException(exception);
}
classpathEntries.add
(JavaCore.newVariableEntry
(*new *Path(mangledName), null, null, null, *new *IClasspathAttribute [] { JavaCore.newClasspathAttribute(PLUGIN_ID_CLASSPATH_ATTRIBUTE _NAME, pluginID) }, *true*));
}
}
}|
agad wrote:
> So, can I define a variable or user library in "Cretate my project"
> wizard? I would like user need do nothing after wizard ends its job
> (like now, when the path is hardocored) and importing such project
> would be easy to (now user need to change 22 jar paths, which are
> provided with one plugin).
>
> Ed Merks wrote:
>
>> I don't think there are any symbolic variables that would definitely
>> work for this purpose (because plugins could be installed in places
>> like the dropins folder or using link files). You could define a
>> variable yourself for just that one jar and then the other users
>> would need to define it as well. Note that even if you aren't
>> developing a plugin, you'd likely find that making your project a
>> plugin project will make it easier to manage the classpath. The
>> scenario you describe would work very well, for example.
>
>
>> agad wrote:
>>> I create java example project which needs some jar files provided by
>>> a plug-in.
>>> When creating this project by wizard it works properly and has
>>> correct paths, but when I import it to another eclipse I need to
>>> change the path. I would like to have in .classpath file paths
>>> relative to plug-in location. Is is possible?
>>>
>
>
--------------010104060708010604030004
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">
Agad,<br>
<br>
We have some somewhat brutal code like this that determines the
classpath for plugins and creates variables to put on the classpath of
a generated project, but we generally avoid that now by always creating
a project with a PDE nature:<br>
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff">
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07654 seconds