Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Accessing properties file through jar
Accessing properties file through jar [message #660359] Fri, 18 March 2011 01:45 Go to next message
Eclipse UserFriend
There are jar plugins in my project. One jar needs access of PROPERTIES file from other jar. Then how to access that PROPERTIES file in jar?
Re: Accessing properties file through jar [message #662323 is a reply to message #660359] Wed, 30 March 2011 05:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Swan,
I am glad I can help you and other newsgroup users:

String pluginLocation = getPluginLocation(PLUGIN_ID);

if (pluginLocation.endsWith(".jar!/")) { //compressed content
URL url = new URL("jar:" + pluginLocation);

JarURLConnection jarConnection = (JarURLConnection) url.openConnection();

JarFile jarFile = jarConnection.getJarFile();

ZipEntry fileEntry = jarFile.getEntry("META-INF/MANIFEST.MF");
}


and the main trick is in the method:

public static String getPluginLocation(String pluginId) {
URL result = Platform.getBundle( pluginId ).getEntry("/");
try {
result = FileLocator.resolve(result);
}
catch (IOException ioe){}

String filePath = result.getFile();

if ( filePath.startsWith("file:")) {
return filePath;
}
else
if ( System.getProperty("os.name").toLowerCase().contains("windows ") ) {

return filePath.substring(1); // fix "\c:[...]"
}
else {
return filePath;
}
}

Sorry for the bad formatting and I hope that helps,
Aleks
Re: Accessing properties file through jar [message #662394 is a reply to message #662323] Wed, 30 March 2011 10:10 Go to previous messageGo to next message
Eclipse UserFriend
It's actually much easier than that:

import org.osgi.framework.Bundle;
import org.eclipse.core.runtime.Platform;

...

Bundle bundle = Platform.getBundle("com.example.otherbundle.pluginid");
URL entry = bundle.getEntry("/path/to/properties"); // path is relative to the bundle (project) root, e.g. "/META-INF/app.properties"


From there you should be able to do what you need with the file. Be sure you check the build.properties of your project to be sure the file you need is included in the binary build or you will be surprised when you go to deploy, speaking from experience. If you need further help, the Equinox or OSGi newsgroups should be more helpful.

Cole
Re: Accessing properties file through jar [message #662626 is a reply to message #662394] Thu, 31 March 2011 06:42 Go to previous message
Eclipse UserFriend
Thanks a lot !!
Previous Topic:SelectionListener on Buttons type SWT.RADIO
Next Topic:WorkbenchPage setPerspective - CoolBar problem
Goto Forum:
  


Current Time: Wed Jul 02 18:13:58 EDT 2025

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

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

Back to the top