2013年11月1日星期五

RCP using sqllite database, how the database files are packaged into products

 This post last edited by the nononojkl on 2012-05-24 11:31:42
the eclipse under development a rcp, uses sqllite database , source code database files (test.db) with the same directory as the src folder . The product comes with rcp out Discovery Database Publishing Wizard export impossible . But in the product 's testing to normal use. Paste segment database connection code , do not know if this will be problems after packing
Class.forName("org.sqlite.JDBC");
URL p = FileLocator.find(Activator.getDefault().getBundle(), new Path("test.db"), null);
p = FileLocator.resolve(p);
String path = p.getPath();
Connection conn = DriverManager.getConnection("jdbc:sqlite:" + path);

------ Solution ------------------------------------- -------


 // if the bundle is not ready then there is no image
        Bundle bundle = Platform.getBundle(pluginId);
        if (!BundleUtility.isReady(bundle)) {
return null;
}

        // look for the image (this will check both the plugin and fragment folders
        URL fullPathString = BundleUtility.find(bundle, imageFilePath);
        if (fullPathString == null) {
            try {
                fullPathString = new URL(imageFilePath);
            } catch (MalformedURLException e) {
                return null;
            }
        }









In fact , you put files on the workspace directory to take the most convenient.
------ For reference only -------------------------------------- -
up next , playing out of the product , plug-in directory jar package which already contains the db files are not accessible databases bag or jar path wrong yet.
------ For reference only -------------------------------------- -
you can not put db files in source folder, can be placed in the root directory of the plug-ins , or icon directory, or self-built a directory, run this plug-in will automatically extract from a resource file , so that you can visit.
------ For reference only -------------------------------------- -
Oh, this problem does not seem to give you reference the code

// Bundle发布路径后缀
static String RUNPATH_SUFFIX = "\\1\\.cp\\";

private String getPubBundlePath(Bundle bundle) {

if (bundle != null) {
File dataDir = bundle.getBundleContext().getDataFile("");
String sDir = dataDir.getAbsolutePath();
String cpDir = sDir.substring(0, sDir.lastIndexOf("\\data"))
+ RUNPATH_SUFFIX;
return cpDir;
}
return "";
}



// 得到当前元素的目录
Bundle bundle = Activator.getDefault().getBundle();
// 发布状态下资源路径
String publishBundlePath = getPubBundlePath(bundle);
if(Platform.inDevelopmentMode()){
URL url = null;

url = bundle.getEntry(htmlFileName);
try {
url = FileLocator.resolve(url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
else
{
new File(publishBundlePath+htmlFileName).getAbsolutePath();
}



------ For reference only ----------------------------------- ----
ask how to solve the same problem

没有评论:

发表评论