VMware {code} Community
CathyBr
Enthusiast
Enthusiast
Jump to solution

vSphere Client SDK V6.7U2- local plugin, finding files which are located in provider.jar is broken

We have text files which are located in the .jar file of our  plug-in data provider.

They are only needed for certain views - some are .json and some are .xml.

The files are read using the path which was retrieved as follows:

String baseDirString = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile() + "files/textFiles";

Of course, with the new tomcat - this resolves to a bad path -

/usr/lib/vmware-vsphere-ui/server/work/Catalina/localhost/ROOT/eclipse/configuration/org.eclipse.osgi/317/0/bundleFilefiles/textFiles -

can someone suggest how to access these files?  The bundleFile seems to be a container of some sort not a directory...

thanks

Cathy

0 Kudos
1 Solution

Accepted Solutions
Plam_Dimitrov
VMware Employee
VMware Employee
Jump to solution

Hi Cathy,

The correct way is to use the class loader of a class located within the jar to load the resource.

For example:

ClassLoader cl = MyConfigurationLoader.class.getClassLoader();
InputStream fileStream = cl.getResourceAsStream(filename);

Regards,

Plam

View solution in original post

0 Kudos
2 Replies
Plam_Dimitrov
VMware Employee
VMware Employee
Jump to solution

Hi Cathy,

The correct way is to use the class loader of a class located within the jar to load the resource.

For example:

ClassLoader cl = MyConfigurationLoader.class.getClassLoader();
InputStream fileStream = cl.getResourceAsStream(filename);

Regards,

Plam

0 Kudos
CathyBr
Enthusiast
Enthusiast
Jump to solution

Thanks Plam!

That worked for both the older and newer versions!

Cathy

0 Kudos