rcp classpath

来源:互联网 发布:ps4经典游戏知乎 编辑:程序博客网 时间:2024/06/01 07:27

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

 

原创粉丝点击