Page 1 of 1

How to read a folder inside resources of oxygen plugin jar

Posted: Wed Aug 24, 2022 4:16 pm
by vishwavaranasi
Hello Team , this might be a general java question , we have a requirement where we have a DB wallet folder inside resources
like oxygen-plugin-project\src\main\resources\Wallet_DB (this folder contains the information to connect to JDBC)

and we tried reading the same folder path inside public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess)
as below

String folderPath=xxxWorkspaceAccessPluginExtension.class.getClassLoader().getResource("Wallet_DB ").getPath();
folderPath=folderPath.replaceAll("file:","");
System.out.println("folderPath" + folderPath);

String DB_URL = "jdbc:oracle:thin:@devdb_medium?TNS_ADMIN="+folderPath;


but the folderPath throwing null pointer exception

Re: How to read a folder inside resources of oxygen plugin jar

Posted: Thu Aug 25, 2022 7:24 am
by Radu
Hi,

After your add-on is built and deployed in Oxygen, where is the "Wallet_DB" file present inside your add-on? Is it present inside a JAR library? In what folder path is it present inside the JAR library?

Regards,
Radu

Re: How to read a folder inside resources of oxygen plugin jar

Posted: Thu Aug 25, 2022 12:59 pm
by vishwavaranasi
"Wallet_DB" is a folder( which will have all the files like tnsnames.ora and other files required to connect DB)
this folder bundled inside myplugin.jar

C:\Program Files\Oxygen XML Editor 24\plugins\myplugin\lib\myplugin.jar

if i unzip the myplugin.jar
the folder appears at the root of the folder myplugin\Wallet_DB

Re: How to read a folder inside resources of oxygen plugin jar

Posted: Thu Aug 25, 2022 1:18 pm
by Radu
Hi,

The Java method "java.lang.ClassLoader.getResource(String)" works only for references to file-like resources.
For example if in the folder "Wallet_DB" you have a file named "marker.txt", you could retrieve the path to it like "ClassLoader.getResource("Wallet_DB/marker.txt")", but it does not work for folder like resources.
https://docs.oracle.com/javase/7/docs/a ... ng.String)

Regards,
Radu