Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Accessing properties file through jar
Accessing properties file through jar [message #660359] Fri, 18 March 2011 05:45 Go to next message
Swap  is currently offline Swap Friend
Messages: 30
Registered: March 2011
Member
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 09:07 Go to previous messageGo to next message
Aleksandar Pavlov is currently offline Aleksandar PavlovFriend
Messages: 79
Registered: July 2009
Member
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 14:10 Go to previous messageGo to next message
Cole Markham is currently offline Cole MarkhamFriend
Messages: 150
Registered: July 2009
Location: College Station, TX
Senior Member

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 10:42 Go to previous message
Swap  is currently offline Swap Friend
Messages: 30
Registered: March 2011
Member
Thanks a lot !!
Previous Topic:SelectionListener on Buttons type SWT.RADIO
Next Topic:WorkbenchPage setPerspective - CoolBar problem
Goto Forum:
  


Current Time: Wed Sep 25 15:01:44 GMT 2024

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

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

Back to the top