Wearybands
Wearybands

Reputation: 2455

Eclipse plugin with external third party jar

I have an RCP application which includes different plugins. In one of the plugin I am using an external third party jar. Due to copyrights reasons I cannot bundle that jar into my product. So I try to include the jar as external jar at runtime. what I have done is as follows

In the Plugin manifest.mf I have

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: EaCom-plugin;singleton:=true
Bundle-Version: 2.1.0
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .,
 external:$eaapi_location$/eaapi.jar
Bundle-NativeCode: external:$eaapi_location$/SSJavaCOM.dll
Export-Package: org.sparx
Bundle-Vendor: %pluginVendor

Under Runtime -> Exported Packages I added

 org.sparx

Under the classpath I have

  external:$eaapi_location$/eaapi.jar

build.properties

source.. = src/main/java/,\
       src/main/scala/,\
       src/main/resources/,\
       src/test/java/,\
       src/test/scala/,\
       src/test/resources/
output.. = bin/
bin.includes = META-INF/,\

In the build.properties I have a warning on the very first line. The warning is

source.external:$eaapi_location$/eaapi.jar build entry is missing

I export the product: myrcpapp.exe and in the config file of my product myrcpapp.ini add vm arguments:-Deaapi_location=C:/JavaAPI

I get the following error

error message : java.lang.error: unresolved compilation problems: Repository cannot be resolved into a type

Though it works fine when I run in eclipse What I am missing ?

Any help will be highly appreciated.

Thanks

Upvotes: 2

Views: 1811

Answers (3)

Wearybands
Wearybands

Reputation: 2455

Ok I Solved my problem. The actual scenario was that I had a third part jar which was included in the wrapper plugin project and is required by other plugins to compile successfully. During the compilation (exporting the product) these other plugins uses the jar located in the wrapper plugin for successful compilation and for that I needed to provide the location of the jar under the java classpath of the wrapper plugin.

But once the the product is exported I didn't want this jar to be the part of the product, since its a third party jar and it should not be distributed with the exe. So the solution is

Under the wrapper plugin Manifest -> Runtime Tab -> Classpath provide the location of the jar. In my case it was

 src/main/resources/thridparty.jar 

Under the Build tab -> Binary Build select only manifest.

In the MANIFEST.MF include

Bundle-ClassPath: external:$thirdpartyjar_location$/thirdparty.jar,
src/main/resources/thirdparty.jar

Export the product and under the product configuration file add the system property

 -Dthirdpartyjar_location=path/to/the/thirdpartyjar

When you run the product using the exe it will use the jar from external path you provided in configuration.

Hope it will help someone.

Upvotes: 4

Nick Wilson
Nick Wilson

Reputation: 4989

Difficult problem to solve, but I think BJ Hargrave's answer here (https://stackoverflow.com/a/19552056/1257372) which suggest putting the jars on the classpath and getting the system bundle to export them is probably the best way.

You can configure the additional system bundle exports by adding a few lines to your application ini file:

org.osgi.framework.system.packages.extra= \
org.thirdparty.xxx; version=1.0

As an alternative the way we got round this was to wrap the application in an installer. The installation wizard displays the licence to the user and prompts them to download the third party libraries. The installer then adds them to the application. More work to set up, but makes the end users job easier.

Upvotes: 0

fmcato
fmcato

Reputation: 172

In the manifest you need to import the external packages you are using:

Import-Package: org.thirdparty.xxx,org.thirdparty.yyy

Upvotes: -1

Related Questions