How to load additional jar in the eclipse plugin ClassLoader - eclipse

I am working on a eclipse plugin and I am willing to use JavaFx in Eclipse org.eclipse.ui.part.EditorPart to create a editor panel.
It seems I have to override method void createPartControl(Composite composite), javafx.embed.swt.FXCanvas is the bridge of Composite and JavaFx Sence(as shown in the document http://docs.oracle.com/javafx/2/swt_interoperability/jfxpub-swt_interoperability.htm). But javafx.embed.swt.FXCanvas is in "$JAVA_HOME/jre/lib/jfxswt.jar" which is not a default loaded component by JVM or Eclipse.
How can I make eclipse load "jfxswt.jar" and my plugin at same time(same ClassLoader) at runtime? Or is there another way to do make it work?

Place jar in lib folder of project and add this jar to build path. It would be automatically accessible to the project and running eclipse plugin.

Add all required jars in 'plugins' folder of eclipse and right click on your project, Remove and Again add runtime plugin dependency, it will add all jars needed by project.

Related

Eclipse plugin: How to force it to use a specific version of SWT.jar?

My eclipse plugin has an external lib that requires SWT 3.75M or above. Therefore I added the corresponding jar file to the class path. Now if I write a test driver to instantiate and call some classes and methods of the lib it works, but if I start my whole plugin and want to call the same methods from there, it doesn't work, because the SWT is below 3.75M
I assume that the problem is, that the plugin does not use the SWT from my lib folder (that I added to the plugin using the appropriate tab in plugin.xml) but the SWT jar from the Eclipse installation. How can I avoid that?
You should use SWT in your plugin as a bundle/plugin (rather than putting the Jar file in your classpath). And then you can specify when you reference the bundle the minimum version that you require. Do this in the manifest of the plugin that references SWT. You will then need to make sure the desired SWT plugin is available in your target platform.

add jar to eclipse plugin (hadoop)

I need to run an Eclipse (Indigo version) plugin, but from the error log I find out that I am missing 2 jars.
How can I add the missing jar to Eclipse so that I can run the plugin?
Is there a way to add the jar to the existing plugin?
If this is of any help, I try to run Hadoop Map/Reduce perspective and I found out that I should add commons-configuration and commons-lang.
The simplest way is to just copy the Jar file(s) into your plugin project, and then go to the plugin manifest (open the MANIFEST.MF file) and add them to the classpath on the Runtime Tab. Also on the Build tab, make sure they are checked so that they are included in the output of the plugin.
There are other ways, like making a special plugin to house only the required Jar files, or get the bundle (plugin) that might already contain that Jar file from someplace like Orbit.

How to have Netbeans projects export their dependencies like Eclipse does?

In Eclipse, if a project uses a particular JAR file, I can mark it to provide/export it.
So if another project has a reference to the former, then the particular JAR will be available too.
How can I do that in Netbeans?
In Netbeans you always have to add JAR in the project properties, unless you use some deployment tools.
Right click in your project
Project Properties -> Libraries
Add JAR

Adding jars to a Eclipse PlugIn

I try to build a Eclipse plugin that has to use a self written jar which is dependent on other jars, but I don't get the point where to start with handling jars as seperate PlugIns. Anywhere I have to use just the .jar files or am I wrong?
I think I found a proper solution; the trick is that you have to implement all the files via Eclipse. I just copy here the solution which was posted to news.eclipse.platform:
Include the jars in a plugin:
Use Import > File System to import the jar files into your plugin project, say in the <project>/lib directory.
Use Add... button to add the jars to the classpath section of the plugin.xml > Runtime tab.
Use New... button to add "." library back (with no quotes, of course).
Make sure your binary build exports the new jar files on the plugin.xml > Build tab.
Save
On the project, use context menu > PDE Tools > Update Classpath to correctly add the jars to the eclipse project classpath.
What is a self-written jar?
Normally you turn 3rd party jars into bundles using an OSGi MANIFEST.MF (See New>Plug-in Development>Plug-in from Existing JAR archive) or you include them in your plugin.jar and add extra Bundle-ClassPath entries as mentioned by TomaC.
If you mean at runtime your plugin will create a new jar and needs to load it, that's different, though.
Project Properties -> Java Build Path -> Add External jars. Is this what you are looking for?

How can I add the external jar to the eclipse rcp application?

I tried to add the apache vfs jar file as the runtime dependency. Even though it throws the below error:
java.lang.ClassNotFoundException: org.apache.commons.vfs.VFS
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:489)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:405)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:393)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at file_explorer.View.setInput(View.java:295)
at file_explorer.View.initialize(View.java:130)
How can i resolve this, thanks in advance.
If you are looking for adding the required jars to your project classpath.Add the required files to lib directory in the project structure.Then from project click the 'run time' tab of plugin.xml and add the required jars from the lib directory to the project classpath.
The best way to include external Jar in Eclipse RCP application is to package it as a plugin and then use classic plugin dependency.
Just create a new plugin containing only your Jar. Then in the build tab of the manifest editor, add your jar to the classpath (at the bottom right) and export all its packages in this same runtime tab. Also be sure to check that you jar is checked in the Build tab.
Nevertheless you should be able to use the jar in a Given plugin source code if you only add it to the classpath as I mentioned previously.
Because some other of your plugins may be interested in using the vfs jar and for separtion of concerns matter I think you should wrap it in its own plugin
The easiest way is to find bundle in an existing OSGI bundle repository.
http://bundles.osgi.org/Main/Repository
http://www.springsource.com/repository/app/
http://www.eclipse.org/orbit/
http://www.knopflerfish.org/repo/index.html
springsource repo contains apache VFS bundle
Then you need to add the bundle to the target platform (or just copy it to the dropins folder)
In order to properly install bundle into a newer version of eclipse you should use an existing p2 repository and install bundle from p2 repository into your runtime platform. There are two ways: you could use existing one (like orbit p2 repo), or you could create your own using p2 publisher as described at https://docs.sonatype.org/display/TYCHO/How+to+make+existing+OSGi+bundles+consumable+by+Tycho
Eclipse RCP is an OSGi environment which extends the Java dependency model, so you can't simply take a jar file and hope it works. To use an external jar, you have to build it to a plugin first, which p2-maven-plugin can help, you can follow the readme document.
With the plugin ready, you should install the plugin and add it to MANIFEST.MF. Then restart Eclipse to make the plugin work.
A more easily way, you needn't install the plugin, just follow(but build the jar):
go to plugin.xml -> Runtime tab;
click Add at the classpath section, then add the plugin to classpath;
make sure there is . path in the text area, otherwise New it.