Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Read files from PlugIn
Read files from PlugIn [message #543324] Tue, 29 June 2010 07:05 Go to next message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
Hello,

i using log4J in my RCP application and need the log4j.properties file for the logger configuration.
At the start up of the application (in Acitivator) i configure my
logger with
PropertyConfigurator.configure(PathPropertyFile);


At the moment i read the file from the filesystem, but i want load the property file from the plugin.

PathPropertyFile = "C:\\temp\\log4j.properties";


How i can read the file from the plugin?

I have test it with
private final transient IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
private final transient String configFilePath = wsRoot.getLocation() + File.separator + "log4j.properties";

but here it will be load from the workspace, not from the plugin.

Thx.
Re: Read files from PlugIn [message #543371 is a reply to message #543324] Tue, 29 June 2010 09:00 Go to previous messageGo to next message
Thomas is currently offline ThomasFriend
Messages: 11
Registered: March 2010
Junior Member
Hi,
you can all in the Application class:
Application.class.getResource( "log4j.properties" ) if its in the Application class package

Quote:
URL java.lang.Class.getResource(String name)
Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining class loader of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResource.

Before delegation, an absolute resource name is constructed from the given resource name using this algorithm:

If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
Otherwise, the absolute name is of the following form:
modified_package_name/name

Where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').

Parameters:
name name of the desired resource
Returns:
A java.net.URL object or null if no resource with this name is found
Since:
JDK1.1

[Updated on: Tue, 29 June 2010 09:00]

Report message to a moderator

icon14.gif  Re: Read files from PlugIn [message #543418 is a reply to message #543371] Tue, 29 June 2010 11:30 Go to previous messageGo to next message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
Great Thing,

Thank you !!
Re: Read files from PlugIn [message #547640 is a reply to message #543418] Mon, 19 July 2010 08:55 Go to previous messageGo to next message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
Hello,

i have another question to this topic.

It is possible to get about Application.class.getResource(name) the absolute path of the files in the plugin project?

If i use
Application.class.getResource( "/log/log4j.properties" )

than i get the relative path of the file, but i need the absolute path of the file. Is this with Application.getResource possible?
Or exists therefor other mechanism?

Edit:
I have at the moment the following problems:
With Application.class.getResource i dont geht the absolute path, so i use some System property keys, for exampe "osgi.splashLocation" etc. In my development IDE all works fine, but if i deploy the application, nothing work more.
Therefore i need a mechanism, which get me always the absolute path of the plugin.

THX

[Updated on: Mon, 19 July 2010 15:19]

Report message to a moderator

Re: Read files from PlugIn [message #548246 is a reply to message #547640] Wed, 21 July 2010 08:59 Go to previous messageGo to next message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member

Nobody knwos how i get the absoulte path of a plugin ??
Maybe about the Application or Activator class ??
Re: Read files from PlugIn [message #548278 is a reply to message #548246] Wed, 21 July 2010 10:46 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 21.07.2010 11:00, budili wrote:
>
> Nobody knwos how i get the absoulte path of a plugin ??
> Maybe about the Application or Activator class ??

Given

Bundle bundle = ..;

try:

URL url = FileLocator.find(bundle, Path.ROOT, null);
if (url == null)
return null;
try {
url = FileLocator.toFileURL(url);
} catch (IOException e) {
return null;
}
return Path.fromOSString(url.getPath());

Hint: If you don't have a Bundle object available,
use

Bundle getBundle(String symbolicName)

from Platform to get one.

HTH & Greetings from Bremen,

Daniel Krügler
icon14.gif  Re: Read files from PlugIn [message #548566 is a reply to message #548278] Thu, 22 July 2010 11:25 Go to previous messageGo to next message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
Thank you very much !!!
That works very well.

One simple another question:
I have in my plugin a directory, who contains some files.
If i deploy the rcp application and start my application,
the rcp btw osgi creates folders in the directory "configuration"-->
"org.eclipse.osgi\bundles" etc. who contains a lot of files which i have included in my rcp app.

How works this mechanism in detail?
Re: Read files from PlugIn [message #548593 is a reply to message #548566] Thu, 22 July 2010 12:13 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 22.07.2010 13:25, budili wrote:
> One simple another question:
> I have in my plugin a directory, who contains some files.
> If i deploy the rcp application and start my application, the rcp btw
> osgi creates folders in the directory "configuration"-->
> "org.eclipse.osgi\bundles" etc. who contains a lot of files which i have
> included in my rcp app.
>
> How works this mechanism in detail?

I don't understand the question. Are you referring to the way osgi
manages its configuration area or are referring to the way how the
deployment does prepare this?

a) Its definitively not a simple question, because there are several
ways to configure the location of the configuration area and you need to
check out the deployment code, if you want to know what it does (we
use headless builds).

b) It would help, if you would try to explain what you actually want to
realize, because this is probably easier than to answer to your last
question ;-)

Greetings from Bremen,

Daniel Krügler
Re: Read files from PlugIn [message #549079 is a reply to message #548593] Sat, 24 July 2010 06:38 Go to previous message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
definitely a).

But you are right, thats a very complex question.
I will look at the eclipse wiki sites and others for this topic.
Previous Topic:Can't disable FastView bars
Next Topic:AssertionFailedException on shutdown: The application has not been initialized
Goto Forum:
  


Current Time: Tue Dec 07 13:08:18 GMT 2021

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

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

Back to the top