Hermann,
I have had the same problem. The only solution I got to work is actually
using another class-loader for ojb related work.
public class EclipseHelper {
public static ClassLoader m_classloaderOrig;
public static ClassLoader m_customClassloader;
static {
m_customClassloader = new
PluginClassLoaderWrapper(GeneratorPlugin.getDefault().getBundle());
}
public static void setContextClassLoader() {
if (m_classloaderOrig != null) {
return;
}
m_classloaderOrig =
Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(m_customClassloader);
}
public static void resetContextClassLoader() {
if (m_classloaderOrig != null) {
Thread.currentThread().setContextClassLoader(m_classloaderOrig);
}
m_classloaderOrig = null;
}
}
public class PluginClassLoaderWrapper extends URLClassLoader {
private Bundle m_bundle;
private boolean m_debug = true;
public PluginClassLoaderWrapper(Bundle bundle) {
super(new URL[0]);
m_bundle = bundle;
if (m_debug) {
System.out.println("PluginClassLoaderWrapper: debug
enabled");
System.out.println("Required plug-ins and libraries: ");
URL[] urls = getURLs();
for (int i=0; i<urls.length; i++) {
System.out.println(urls[i]);
}
System.out.println();
}
}
public Class loadClass(String className) throws ClassNotFoundException {
Class clazz = m_bundle.loadClass(className);
if (m_debug)
System.out.println("PluginClassLoaderWrapper.loadClass("
+ className + ") --> " + clazz);
return m_bundle.loadClass(className);
}
public URL findResource(String name) {
URL url = m_bundle.getEntry(name);
if (m_debug)
System.out.println("PluginClassLoaderWrapper.findResource(" + name
+ ") --> " + url);
if (url == null) {
System.out.println("... findResource " + name );
url = m_bundle.getResource(name);
System.out.println("PluginClassLoaderWrapper.findResource2(" + name
+ ") --> " + url);
if (url != null) {
try {
url = Platform.resolve(url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("PluginClassLoaderWrapper.findResource3(" + name
+ ") --> " + url);
}
return url;
}
public URL[] getURLs() {
System.out.println("getURLs: " + m_bundle.getSymbolicName());
Set urls = getPluginClasspath(m_bundle.getSymbolicName());
return (URL[]) urls.toArray(new URL[urls.size()]);
}
protected Set getPluginClasspath(String pluginId) {
// Collect set of plugin-ins
Set plugins = new HashSet();
addPluginPrereqs(pluginId, plugins);
// Collect URLs for each plugin
Set urls = new HashSet();
for (Iterator iter = plugins.iterator(); iter.hasNext();) {
String id = (String) iter.next();
try {
Bundle b = Platform.getBundle(id);
if (b != null) {
String headers = (String)
b.getHeaders().get(
Constants.BUNDLE_CLASSPATH);
ManifestElement[] paths =
ManifestElement.parseHeader(
Constants.BUNDLE_CLASSPATH, headers);
if (paths != null) {
for (int i = 0; i <
paths.length; i++) {
String path =
paths[i].getValue();
URL url =
b.getEntry(path);
if (url != null) {
try {
urls.add(Platform.asLocalURL(url));
} catch
(IOException e) {
}
}
}
}
}
} catch (BundleException e) {
}
}
return urls;
}
private void addPluginPrereqs(String pluginId, Set pluginIds) {
if (pluginIds.contains(pluginId)) {
return;
}
String[] immidiatePrereqs = getDirectPrereqs(pluginId);
for (int i = 0; i < immidiatePrereqs.length; i++) {
addPluginPrereqs(immidiatePrereqs[i], pluginIds);
}
pluginIds.add(pluginId);
}
private String[] getDirectPrereqs(String pluginId) {
try {
Bundle bundle = Platform.getBundle(pluginId);
if (bundle != null) {
String header = (String)
bundle.getHeaders().get(
Constants.REQUIRE_BUNDLE);
ManifestElement[] requires =
ManifestElement.parseHeader(
Constants.REQUIRE_BUNDLE,
header);
if (requires != null) {
String[] reqs = new
String[requires.length];
for (int i = 0; i < requires.length;
i++) {
reqs[i] =
requires[i].getValue();
}
return reqs;
}
}
} catch (BundleException e) {
// TODO: handle exception
}
return new String[0];
}
}
You would then invoke EclipseHelper.setContextClassLoader() before
executiong OJB stuff and EclipseHelper.resetContextClassLoader()
afterwards.
The code is still messy, but it works. Make sure all OJB jars are in the
runtime libraries of your plugin.xml.
Regards,
Chris
From: Gildas Le Qu�r� <gildas.lequere <at> atosorigin.com>
Subject: Re: OJB.properties & Eclipse & Custom location
Newsgroups: gmane.comp.jakarta.ojb.user
Date: Mon, 28 Feb 2005 09:06:43 +0100
Hi Hermann,
Add OJB.properties to the classpath in your application launcher (RUN>select
the classpath tab>Advanced>select Add folder and select your OJB.properties
folder).
regards
Gildas
----- Original Message -----
From: "Ruediger Herrmann" <ruediger.herrmann <at> gmx.de>
To: <ojb-user <at> db.apache.org>
Sent: Saturday, February 26, 2005 7:19 PM
Subject: OJB.properties & Eclipse & Custom location
> Hello World,
>
> I am pretty sure, this question was posted before, though I couldn't find
> it anywhere, moreover this is maybe actually a Eclipse question...
> Here I go:
>
> I'm using OJB in a Eclipse plugin and want to place my OJB.properties in
> a "config" directory wich is a sub-directory of the plugin.
>
> I understand that I must override the location with System.setProperty
> ("OJB.properties", ... ). The override itself works, but the various
> versions I tried never point to the right absolute path.
> To be more accurate: how do I convert a path wich is relative to the
> Eclipse plugin root path to an absolute path;)
>
> A hint where to put the OJB.properties file (in my Eclipse plugin!)
> without overriding the location would serve as well...
>
> Regards
> R�diger Herrmann
>
>
>
> --
> DSL Komplett von GMX +++ Superg�nstig und stressfrei einsteigen!
> AKTION "Kein Einrichtungspreis" nutzen: http://www.gmx.net/de/go/dsl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe <at> db.apache.org
> For additional commands, e-mail: ojb-user-help <at> db.apache.org
>
itrias GmbH
Informatikdienstleistungen
Morgenstrasse 1
CH-3073 G�mligen
Tel: +41 31 333 53 73
Fax: +41 61 272 56 54
Mobile: +41 79 257 85 71
http://www.itrias.com/
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]