ERROR exporting Eclipse Plug-In - java

I'm trying to export an Eclipse Plgug-In in Eclipse Oxygen, but I get the following errors (only 2):
The error is in one of my Java Classes, emitter1, when I use the xerces import and then the Base64 Object below, but when I compile the plug-in in the IDE in runs with no errors,
Here's an image of my projects tree:
The import and the object are being used, like I said, in the emitter1 class,
Does anyone know why this is happening and how to solve it?
Maybe I can't use referenced libraries in plug-in projects, or I have to add them in a different way? What I did was: Right-Click on Project -> Properties -> Java Build Path -> Add External Jars, and added xerces jar
Thank you!
Alexandre Jacinto

You can't use external jars in a plugin. You can only reference code in other plugins or jars which you include as part of your plugin and add to the Bundle-Classpath in the MANIFEST.MF (and also update the build.properties to include the jars in the build).
An example Bundle-Classpath from one of my plug-ins:
Bundle-ClassPath: .,
lib/jogg-0.0.7.jar,
lib/jorbis-0.0.15.jar,
lib/vorbisspi1.0.2.jar
The . is your normal code and the other entries are jars in a lib directory in the plugin project.
The build.properties would include
bin.includes = ....... other things
.,\
lib/jogg-0.0.7.jar,\
lib/jorbis-0.0.15.jar,\
lib/vorbisspi1.0.2.jar
If you use the normal plugin.xml/MANIFEST.MF/build.properties editor you define the bundle classpath on the 'Runtime' tab in the 'Classpath' section and the build.properties on the build.properties tab.
Unfortunately Eclipse doesn't check any of this when you test your plugin within Eclipse. The errors only appear in exported plugins and RCPs.

Related

Manipulate the java class path of an Eclipse plugin?

I am working on a plugin that consist of a homemade view to Eclipse.
When I run the plugin and display the classpath using System.getProperty("java.class.path")
I get this as output : D:\Programs\eclipse\plugins\org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
I would like to add some .jar files for the proper functioning of my view, but I can't figure out how... I guess you can do it by adding some specifications to the MANIFEST.MF of the plugin but I don't know how to do it propely.
any ideas ?
Each Eclipse plugin has its own classpath. To use additional jars in the plugin you need to include them in the plugin.
Add your jars to the plugin directory. Usually they are put in a 'lib' directory.
Open the plugin MANIFEST.MF editor and on the 'Runtime' tab in the 'Classpath' section click the 'Add...' button and add your jars to the class path.
On the 'Build' tab of the editor make sure the 'lib' folder is include in the Binary Build section.
Your MANIFEST.MF should end up with a `Bundle-Classpath' entry that looks something like:
Bundle-ClassPath: .,
lib/jogg-0.0.7.jar,
lib/jorbis-0.0.15.jar,
lib/vorbisspi1.0.2.jar
(here I have 3 jars in a lib folder).
The build.properties file should be something like:
bin.includes = META-INF/,\
.,\
plugin.xml,\
lib/,\
lib/jogg-0.0.7.jar,\
lib/jorbis-0.0.15.jar,\
lib/vorbisspi1.0.2.jar
For Compile time we need to add it to the Project runtime library.
For the run time you have to package the jar either in your EAR/WAR file or Load it to the Application server as a App server libraries.
Please let me know if you need further assistance on this.
The best approach I've found is to create a lib directory in your Eclipse project (where your view is contained). Place your .jar files in said lib directory.
Then using the editor on the MANIFEST.MF, you add the .jar files to the classpath. If you wish to export the packages, you then add to the Exported Packages as well.
Depending upon what you are doing, you may wish/need to also update the Build Configuration.
If you examine the MANIFEST.MF file itself, you will then see an entry for Bundle-ClassPath. It will list your entries. Here it has the standard "." for the project, a resources/ directory that we export, and a couple of .jar files.
Bundle-ClassPath: .,
resources/,
lib/aopalliance-1.0.jar,
lib/apccore-client-2.11.8.jar,
lib/cglib-nodep-2.2.2.jar,
lib/ehcache-2.10.3.jar,
...
Note that in our experience, it is also necessary to adjust the Java Build Path from the Properties of the project itself. A user commented that this step may not be necessary. We are on an older version of Eclipse due to our product, so YMMV, If needed (usually compile failures are the indicator), you then need to add, via the properties context menu on the project, the .jar files to the "Java Build Path" (you can do the same with a resources directory).
This will allow you to properly build using the .jar files.

Eclipse plugin cannot find class from class folder

I'm developing an Eclipse plugin, and want to use some pre-compiled classes which I've put to lib/ folder in my project (so the directory structure looks like {proj_root}/lib/com/example/Required.class). Then I've added lib/ folder as class folder to project's build path. At build time all is working fine, I can import and use that classes in my code. And now the problem is, when I'm running my plugin in separate Eclipse instance I get ClassNotFoundException by my plugin refering to class from precompiled classes folder.I tried specifying my class folder in "Order and export" tab in Build path settings. Also I tried setting checkbox in plugin's build.properties GUI editor in front of lib/ folder to be included in binary build. In that case if I export my plugin to JAR I can see lib/ folder inside it, with my classfiles, but at runtime my plugin still cannot find any of classes from lib/.Can you please give me an advice on how I should tell Eclipse where to find that classes at runtime?
PS.:
I did research on stackoverflow on this problem, but all suggestions are the same: just add class folder in project's Build path.
At this point in plugin's build.properties Text editor, eclipse shows warning The class folder 'lib/' is not associated to any output library entry. and suggests to make this modification of code:
output.. = bin/,lib/. I have tried that solution but it is seems to change nothing with the problem.
It sounds very much like you have added the lib folder to the "Java Build Path" properties page of the plug-in project.
But... for plug-in projects, this does not work as these are OSGi bundles - you must include the lib folder in the PDE Editor on the "Runtime" page:

Eclipse (probably) doesn't compile external jars

Suddenly, all my code depending on external jars doesn't work.
For example:
Jsoup.parse(str)
gives:
could not resolve type: org.jsoup.Jsoup
And i'm 100% sure that it is in the build path.
Maybe it happenned because I updated the ADT plugin and the platform tools to the latest version, but it doesn't make sense...
But it started occuring since I updated those.
So apparently eclipse doesn't compile those jars. (In code, it DOES resolve the jars types)...
Do you maybe know what is the problem?
This has nothing to do with compilation: jar's are already compiled.
You only need to add the jar to your project classpath so Eclipse will know to run java with the .jar. You can do this with "Context/Right click menu->Properties > Java Build Path > Libraries" (source). For portability I recommend placing the .jar in a subdirectory of your project. A "lib" folder in your project root (where "bin" and "src" are too) is commonly used.
Also note that to run your program you will need to add the dependency .jar to your java command, but with a little searching you can find out how to include the dependency .jar in your own combined .jar.
You have to put the libraries in /libs folder of your project (if you are using Eclipse you choose "Add JARs.." not "Add external JARs..")

External jars in eclipse plug-in

I'm creating an eclipse plug-in and I'm having trouble with external jars. In my plug-in I start an application which requires some external jars. What do I have to do to export them automatically with the rest of the plug-in?
Thanks in advance :)
Open your plugin.xml
Go to Runtime tab and add your JAR in the classpath section
By following the steps below, the external JARs will be included when you export your plug-in:
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
Open the build.properties in your plug-in project and check the JARs you want to include in the build in the Binary Build section on the left.
This is an easy way, though it does create an additional plug-in.
In Eclipse:
Choose New>Other, then Plug-in Development>Plug-in from existing JAR archives.
Choose the jars you want to include.
On the next page, configure the plug-in.
In your plug-in's manifest, add the new plug-in as a dependency.
In your plug-in's Properties, add the new project under Java Build Path on the Projects tab.
Edit: You may be able to combine the jars into your plug-in by instead combining both suggestions of Zsolt and user714965 below.
This is what has worked for me. If they are truly external, and this is a project for your company that is not going to be in the "wild" and you control the environment, and you have them out on the file system say at /opt/java/lib/somedir/some.jar you can tell the bundle where to find them by adding them to the Bundle-ClassPath entry in the MANIFEST.MF under META-INF. The syntax is:
Bundle-ClassPath: .,
external:/opt/java/lib/somedir/some.jar,
external:/opt/java/lib/someotherdir/someother.jar
Also it would be prudent to use these in your build path so that you are working with the same jars in both build and runtime environments.
I have done this where the Jars are multi-purpose (such as apache-commons) on our file systems and again we control the environment.
Reference the following:
http://www.eclipsezone.com/eclipse/forums/t51870.html
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
..but as apposed to Zsolt Török (his solution did not work for me) I double-clicked on the plugin.xml, went to the build tab, at the bottom, I clicked Add JARs..., and hey presto, it showed my project, and I then navigated to lib and included the external jar, as per step 1.
The approach from Andy Thomas mostly works, but you also need to export the packages needed by the existing plugin in the new wrapper plugin so that they can be accessed by the plugin at runtime.

Runtime issues during developing an Eclipse Plugin

Right now, I am trying to create a plug-in of Eclipse which depends on other jar; therefore, I created a plug-in base on the jar and deployed it under my Eclipses' plugin foler. It works well when I start it from my working environment via an Eclipse. However, as soon as I have exported it into a jar and have deployed into Eclipse, it not work any more as it couldn't find out the dependent jar. What happened and how to solve the issue? Does anyone know that? please save me.
The MANIFEST.MF has a Tab called "Dependencies" in which alle plugins should placed the current plugin depends on.
At runtime you have to place the "dependencies" plugins in the same folder as the one you want to start or you want to work with.
When a plugin has jars it should use, you have to put the jars to the "Runtime" Classpath Entry and you should add the jar to the "Build" Binary Build entry.
Also, does the plugin.xml associated with your 'external jar' plugin does export the right packages ?
Did you check this article describing all steps necessary to packaging 3rd party jars as plug-ins ?
Other very important points are described in the article PDE and 3rdParty Bundles in OSGI Enterprise apps with rules such as:
Always put dependent JAR Files in separate bundles and describe the dependencies in your Manifest file. Don't hide those JARs in your own bundle.
If possible use Import-Package to resolve your dependencies.
Export only your "public" packages - no internal.
Use Require-Bundle only to resolve dependencies inside your own „universe“, not against common bundles.
Always version Require-Bundle, Import-Package und Export-Package.
Require-Bundle always has a dependency to a bundle with a specific name.
Import-Package isn't dependent from the name of the bundle, so its more flexible. Of course its more work to look at your packages and decide which you need to import or to export compared to a one-liner with Require-Bundle
If a bundle itself contains packages inside the bundle and exports them, never put these packages also into the Manifest as imported packages.
Before deploying of a bundle as plug-in be sure the Package-Uses are re-calculated. Wrong Package-Use entries for exported packages can stop PDE to export your Plug-In.
The working behavior out of Eclipse is normal, since the dependent jar is in the classpath of the project.
Have you had a look at the plugin folder you deployed? I suspect, that the dependency isn't contained in the plugin folder.
I just had a similar problem. I fixed it using the plugin view:
Add jar using the Classpath section of the Runtime tab
Use the Organise Manifest Wizard from the Overview tab to do all the required manifest changes
Use the Export Wizard from the Overview tab to export the finished plugin.
Note I am using Eclipse 3.3 so your milage may vary.

Categories

Resources