OpenOffice is an excellent open source office suite that contributes to open source communities by Sun. If inheriting it under Eclipse, it is equivalent to adding support for the office suite to Eclipse. To this end, the author tried, as follows.
OpenOffice provides several JAR packages that provide a way to embed OpenOffice and call the OpenOffice service in Java. In the example thereof, OfficBean and OfficeDev are available for reference. However, if they use SWT_AWT to embed them directly, they can not find an exception of the OfficeBean library. After analysis, the following code was used when the LocalOfficeConnection file in Officeben.jar loaded the OfficeBean library:
String asharedlibname = getProgramPath () java.io.file.seParetor system.maplibraryName (office_lib_name); System.Load (ashaaredlibname);
GetProgrampath () adopts
File path = nativelibraryloader.getResource (this.getClass (). GetClassLoader (), aexec); where Aexec is a Soffice.exe file, that is, OpenOffice start file name. NativeLibraryLoader.getResource loads the resource using ClassLoader.getResource (s).
The problem appears in the final classloader.getResource (s). In a normal Java program, just set the pathOffice path in the PATH path, and passes the OpenOffice path to ClassPath, you can find Soffice.exe correctly via ClassLoader.GetResource (s), so that you can correctly get the path path of AsharedLibname. . But under Eclipse, no matter how to set PATH and pass ClassPath, you cannot find Soffice to load the library error.
After finding the root of the problem, you can modify getprogrampath () directly. In order to install OpenOffice on the client, copy the directory after the OpenOffice installation to the plugin directory, and then use the following code to get the directory of the plugin:
. MProgramPath = Platform.getBundle ( "org.openoffice") getLocation () "program"; if (mProgramPath.indexOf ( "@ /")> 0) {mProgramPath = mProgramPath.substring (mProgramPath.indexOf ( "@ /" ) 2);} This can be loaded. But don't forget to set the above path in PATH, because OfficeBean uses the default mode when loading other components, must set the path in the PATH to find it correctly. This requires the production installer and writes this path into the PATH by the installer.