Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Library plugin - config files
Library plugin - config files [message #449167] Wed, 10 May 2006 15:32 Go to next message
Eclipse UserFriend
Hi,

I had an RCP application with all the third party libraries in
classpath under lib folder. All works fine, I have now decided to move
the third party libraries to a different plugin because everytime I
release a new version for my plugin users have to download the libraries
too which hardly ever change.

I have created a library plugin having all the third party libraries
for eg log4j and hibernate. This plugin is included in my plugin's
dependencies which solves all compilation problems. When I run the
application it can find the libraries but log4j fails to find the
configuration files which is kept in src folder of my application
plugin. Similarly hibernate cannot find hibernate.cfg.xml file which is
also in src folder. I have tried moving these files to different places
including in my library plugin but nothing works.

What am I doing wrong? Shouldnt these files be picked form their usual
positions?

Thanks,
Amit.
Re: Library plugin - config files [message #449169 is a reply to message #449167] Wed, 10 May 2006 15:47 Go to previous messageGo to next message
Eclipse UserFriend
Go to Build Tab on plugin.xml editor and check the files that you wanna be
deploid in your plugin.

"Amit Rana" <amit.rana@gmail.com> wrote in message
news:e3tf8t$212$1@utils.eclipse.org...
> Hi,
>
> I had an RCP application with all the third party libraries in
> classpath under lib folder. All works fine, I have now decided to move
> the third party libraries to a different plugin because everytime I
> release a new version for my plugin users have to download the libraries
> too which hardly ever change.
>
> I have created a library plugin having all the third party libraries
> for eg log4j and hibernate. This plugin is included in my plugin's
> dependencies which solves all compilation problems. When I run the
> application it can find the libraries but log4j fails to find the
> configuration files which is kept in src folder of my application
> plugin. Similarly hibernate cannot find hibernate.cfg.xml file which is
> also in src folder. I have tried moving these files to different places
> including in my library plugin but nothing works.
>
> What am I doing wrong? Shouldnt these files be picked form their usual
> positions?
>
> Thanks,
> Amit.
Re: Library plugin - config files [message #449170 is a reply to message #449169] Wed, 10 May 2006 16:23 Go to previous messageGo to next message
Eclipse UserFriend
Hello Mauro,
Thanks for responding.

I checked and all the required files (including the log4j.xml,
hibernate.cfg.xml) are selected.

My app is not even recognising these files in PDE runtime.


Mauro wrote:
> Go to Build Tab on plugin.xml editor and check the files that you wanna be
> deploid in your plugin.
>
> "Amit Rana" <amit.rana@gmail.com> wrote in message
> news:e3tf8t$212$1@utils.eclipse.org...
>> Hi,
>>
>> I had an RCP application with all the third party libraries in
>> classpath under lib folder. All works fine, I have now decided to move
>> the third party libraries to a different plugin because everytime I
>> release a new version for my plugin users have to download the libraries
>> too which hardly ever change.
>>
>> I have created a library plugin having all the third party libraries
>> for eg log4j and hibernate. This plugin is included in my plugin's
>> dependencies which solves all compilation problems. When I run the
>> application it can find the libraries but log4j fails to find the
>> configuration files which is kept in src folder of my application
>> plugin. Similarly hibernate cannot find hibernate.cfg.xml file which is
>> also in src folder. I have tried moving these files to different places
>> including in my library plugin but nothing works.
>>
>> What am I doing wrong? Shouldnt these files be picked form their usual
>> positions?
>>
>> Thanks,
>> Amit.
>
>
Re: Library plugin - config files [message #449172 is a reply to message #449170] Wed, 10 May 2006 16:50 Go to previous messageGo to next message
Eclipse UserFriend
Amit Rana wrote:

> Hello Mauro,
> Thanks for responding.
>
> I checked and all the required files (including the log4j.xml,
> hibernate.cfg.xml) are selected.
>
> My app is not even recognising these files in PDE runtime.

If previously those libraries were finding those files automatically
through some relative path or your were telling the libraries where to
find those files using a relative path that relative path will now be
broken. I do not know the API for those libraries from your example but
if you know how to tell those libraries where to find a config file you
can determine a real file system path to point them to. Here is an
example that sets up the system property to find a .dll for JNI usage
(with non relevant code removed - so even though this comes from a working
system I have not compiled this exact snippet).

1 // Get the bundle object
2 Bundle bundle = MyPlugin.getDefault ().getBundle ();
3
4 // Find the lib directory
5 String libDirectoryPath = null;
6 URL bundleLocation = bundle.getEntry ("/lib");
7 try {
8 // Resolve the URL
9 URL libURL = Platform.resolve (bundleLocation);
10 File libDirectory = new File (libURL.getFile ());
11 libDirectoryPath = libDirectory.toString ();
12
13 // Add the lib directory to the system's library path
14 String systemLibraryPath = System.getProperty ("java.library.path");
15 StringBuffer newLibraryPath = new StringBuffer (libDirectoryPath);
16 newLibraryPath.append (File.pathSeparator).append (systemLibraryPath);
17 System.setProperty ("java.library.path", newLibraryPath.toString());
18 } catch (Exception e) {
19 // Report the problem some how
20 }

At line 6 the path for getEntry is relative to your plug-in's root. So
your congif files need to be in a top level directory under your plug-in.
After you resolve your location as in line 9 the URL now points to the
file in a way that will allow you to get a file path.

Ian
Re: Library plugin - config files [message #449232 is a reply to message #449172] Thu, 11 May 2006 06:24 Go to previous messageGo to next message
Eclipse UserFriend
Hello Ian,

Thanks for the response and the sample code.

> If previously those libraries were finding those files automatically
> through some relative path or your were telling the libraries where to
> find those files using a relative path that relative path will now be
> broken.
These libraries were finding the files automatically from classpath.
Although there is option to specify the file as well but that doesnt
solve the problem.

I tried your code now by manually specifying the file
(hibernate.cfg.xml) it did went to second step but failed again as it
couldnt find other xml files that its supposed to pick up from the classpth.

Why is this happenning? Even after setting java.library.path to bin
folder it still cant find those files?

Ian Leslie wrote:
> Amit Rana wrote:
>
>> Hello Mauro,
>> Thanks for responding.
>>
>> I checked and all the required files (including the log4j.xml,
>> hibernate.cfg.xml) are selected.
>>
>> My app is not even recognising these files in PDE runtime.
>
> If previously those libraries were finding those files automatically
> through some relative path or your were telling the libraries where to
> find those files using a relative path that relative path will now be
> broken. I do not know the API for those libraries from your example but
> if you know how to tell those libraries where to find a config file you
> can determine a real file system path to point them to. Here is an
> example that sets up the system property to find a .dll for JNI usage
> (with non relevant code removed - so even though this comes from a
> working system I have not compiled this exact snippet).
>
> 1 // Get the bundle object
> 2 Bundle bundle = MyPlugin.getDefault ().getBundle ();
> 3
> 4 // Find the lib directory
> 5 String libDirectoryPath = null;
> 6 URL bundleLocation = bundle.getEntry ("/lib");
> 7 try {
> 8 // Resolve the URL
> 9 URL libURL = Platform.resolve (bundleLocation);
> 10 File libDirectory = new File (libURL.getFile ());
> 11 libDirectoryPath = libDirectory.toString ();
> 12
> 13 // Add the lib directory to the system's library path
> 14 String systemLibraryPath = System.getProperty
> ("java.library.path");
> 15 StringBuffer newLibraryPath = new StringBuffer
> (libDirectoryPath);
> 16 newLibraryPath.append (File.pathSeparator).append
> (systemLibraryPath);
> 17 System.setProperty ("java.library.path",
> newLibraryPath.toString());
> 18 } catch (Exception e) {
> 19 // Report the problem some how
> 20 }
>
> At line 6 the path for getEntry is relative to your plug-in's root. So
> your congif files need to be in a top level directory under your
> plug-in. After you resolve your location as in line 9 the URL now
> points to the file in a way that will allow you to get a file path.
> Ian
>
>
Re: Library plugin - config files [message #449238 is a reply to message #449232] Thu, 11 May 2006 07:46 Go to previous messageGo to next message
Eclipse UserFriend
Amit Rana wrote:

> Hello Ian,

> Thanks for the response and the sample code.

> > If previously those libraries were finding those files automatically
> > through some relative path or your were telling the libraries where to
> > find those files using a relative path that relative path will now be
> > broken.
> These libraries were finding the files automatically from classpath.
> Although there is option to specify the file as well but that doesnt
> solve the problem.

> I tried your code now by manually specifying the file
> (hibernate.cfg.xml) it did went to second step but failed again as it
> couldnt find other xml files that its supposed to pick up from the classpth.

> Why is this happenning? Even after setting java.library.path to bin
> folder it still cant find those files?

Ah the class path. In eclipse the class path is "replaced" by the plug-in
dependencies. So the libraries that are in the library plug-in do not see
the your client plug-in as being on the class path.

Setting java.library.path will have no effect on searches via the class
path. Setting java.library.path is the right thing to do so that java
classes can find their JNI library which is what my sample code needed to
do. In your case you need to tell the library where the .xml files are
located by what ever means that libary's API indicates.

Ian
Re: Library plugin - config files [message #449253 is a reply to message #449167] Thu, 11 May 2006 09:18 Go to previous messageGo to next message
Eclipse UserFriend
For using 3rd party jars, especially across multiple plugins, make sure
you use a list like http://wiki.eclipse.org/index.php/PDE

Also, if you search for eclipse and log4j or eclipse and hibernate, you
should be able to find a lot of articles describing how to solve your
problem. i.e. one solution is buddy classloading.

Later,
PW
Re: Library plugin - config files [message #449374 is a reply to message #449238] Thu, 11 May 2006 11:17 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for response.

hmmm!! is it possible that this might be some privilege issue i.e.
external libraries i.e. dependent plugins do not have access to the
classess or files in original plugin/app? It sounds odd that main
application can access files in dependent plugins but not vice versa
given that these are in same classpath.

any ideas?

Ian Leslie wrote:
> Amit Rana wrote:
>
>> Hello Ian,
>
>> Thanks for the response and the sample code.
>
>> > If previously those libraries were finding those files automatically
>> > through some relative path or your were telling the libraries where to
>> > find those files using a relative path that relative path will now be
>> > broken.
>> These libraries were finding the files automatically from classpath.
>> Although there is option to specify the file as well but that doesnt
>> solve the problem.
>
>> I tried your code now by manually specifying the file
>> (hibernate.cfg.xml) it did went to second step but failed again as it
>> couldnt find other xml files that its supposed to pick up from the
>> classpth.
>
>> Why is this happenning? Even after setting java.library.path to bin
>> folder it still cant find those files?
>
> Ah the class path. In eclipse the class path is "replaced" by the
> plug-in dependencies. So the libraries that are in the library plug-in
> do not see the your client plug-in as being on the class path.
> Setting java.library.path will have no effect on searches via the class
> path. Setting java.library.path is the right thing to do so that java
> classes can find their JNI library which is what my sample code needed
> to do. In your case you need to tell the library where the .xml files
> are located by what ever means that libary's API indicates.
>
> Ian
>
Re: Library plugin - config files [message #449379 is a reply to message #449253] Thu, 11 May 2006 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Hello Ian, Paul,

Thanks for taking time to respond. I did google for log4j and eclipse
because I read somewhere that eclipse in action talks about creating a
library plugin for log4j.
Anyway searched again for "eclipse log4j buddy classloading" and found
http://www.eclipsezone.com/articles/eclipse-vms/ which talks about this
issue in good detail.

Thanks again.

Regards,
Amit.

Paul Webster wrote:
> For using 3rd party jars, especially across multiple plugins, make sure
> you use a list like http://wiki.eclipse.org/index.php/PDE
>
> Also, if you search for eclipse and log4j or eclipse and hibernate, you
> should be able to find a lot of articles describing how to solve your
> problem. i.e. one solution is buddy classloading.
>
> Later,
> PW
Re: Library plugin - config files [message #449387 is a reply to message #449374] Thu, 11 May 2006 14:00 Go to previous message
Eclipse UserFriend
Amit Rana wrote:

> Thanks for response.

> hmmm!! is it possible that this might be some privilege issue i.e.
> external libraries i.e. dependent plugins do not have access to the
> classess or files in original plugin/app? It sounds odd that main
> application can access files in dependent plugins but not vice versa
> given that these are in same classpath.

> any ideas?

That is just it though the "classpath" for a plug-in is made up of that
plug-in plus all plug-ins that it depends on. Consider a simplified
example: we have a library plug-in org.test.commonlibs and a client
plug-in that uses those libraries called org.test.client. For code in the
commonlibs plug-in the "classpath" does *not* include classes from the
client plug-in. But code in your client plug-in can use classes in the
commonlibs plug-in.

Ian
Previous Topic:Question re-asked: how toassociate the part with its secondary view id?
Next Topic:closing editor when isDirty() == true
Goto Forum:
  


Current Time: Sun Aug 31 16:47:33 EDT 2025

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

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

Back to the top