How to read a folder inside resources of oxygen plugin jar

Oxygen general issues.
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

How to read a folder inside resources of oxygen plugin jar

Post 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
Thanks,
vishwa
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

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

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

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

Post 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
Thanks,
vishwa
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

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

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply