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.
Related
I have a plain Java project (not a plugin project) which I want to add to a classpath of a eclipse plugin which I am developing. But in web projects I can add that project as a build path and it works fine. But I tried same thing in eclipse plugin, I am able to compile successfully, but at run time I am getting java.lang.ClassNotFoundException.
I know OSGi quite well and I know how to add OSGi into an classpath (using export-packages) but what I want is to add Standard, non-osgi project into an classpath, so that I wont' get runtime errors. Is there anyway I can achieve this?
I can export project as a jar file or make it as a plugin project and it would work fine. But that's not my option currently because, still that API is in pre-alpha stage, and there would be lot of changes going on. So I am trying to avoid pain of exporting it as jar file everytime. Is there any option for me other than this?
I have a similar situation: I want non-OSGi Maven dependencies integrated into the classpath of my plugin. I succeeded with a roundabout solution, which I think is the best I could get.
I have a build step outside of Eclipse where I copy the class files of the dependency into the plugin's lib folder. The lib folder is specified in MANIFEST.MF as an entry in Bundle-ClassPath and (here comes the hack) as a source folder in build.properties. That was the only way to make the plugin work both when launched from within Eclipse and when exported.
I am developing an eclipse plugin. It has other plugin/feature dependencies. However I want to add my own favorite JAR/libriaries to it, like say logback for example. How can I do this so that when I eventually deploy it to an update site, it will have these jars on the classpath?
Also, I am currently using eclipse to run the plugin (it opens another instance of eclipse) to run this. This will also need to have the jar on the classpath.
You can try these steps :-
Use Import>File System to import the jar files into your plugin project, say in the /lib directory.
Use "Add..." to add the jars to the classpath section of the plugin.xml>Runtime tab.
Use "New..." 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.
In plugin-manifest editor select Runtime tab and add you jar in classpath section.
I am working on a Hadoop project in Eclipse that depends on another one of my projects; I've included the other project in my build path, but when I export the dependent project, it only contains the classes from that same project.
Ordinarily, this would not be a problem, as I could just link the other project with the -cp flag, but Hadoop requires you to pass the jar as an argument, meaning that all of my dependencies must be inside that jar.
Is there a way, in Eclipse, to automatically build and include classes from projects that you depend on?
Thanks.
You coud use Ant to automatically build, test and export. It needs some time learning it, but its worth.
There are possible tasks (fileset, zipgroupfileset, copy) to include files, jars (unzipped) or anything into the final jar. By this way you definitly know whats inside your distribution jar and you don't need an eclipe installation running.
I suggest you take a look at maven as a build tool. You define the dependencies and build steps for each of your projects in files called pom files. The maven plugins for Eclipse (the m2e plugins) can take the configuration in the pom file and setup your Eclipse build paths and project description so that you can access the classes in your other project in Eclipse. Maven can also create a jar for you that has the classes from both projects (a "jar-with-dependencies").
In maven terms, your two projects are called "artifacts" with one having a dependency on the other.
The one downside to maven (and the cause for many negative comments about maven) is an initially steep learning curve that can be frustrating. What you're trying to do, however, is very straightforward and I expect you can find a number of examples showing you exactly what you want to do.
The first step, and that's what my answer is about, is to take a look at maven. It may seem overly complex, but it can scale to handle just about any build configuration you need as your hadoop apps get more and more complex.
You can export a project as a Runnable jar, which can be useful if you want a single jar, with dependencies included.
Select the Project. File > Export. Select the Java section. Select Runnable JAR file.
See related answer:
Eclipse: How to build an executable jar with external jar?
I recently switched to IntelliJ IDEA 11 and after what I understand facets is a way to configure frameworks etc. It also downloads the needed libraries.
When you add the EJB facet to a project you get a folder inside the EJB module named lib and it contains jars. What is these libraries used for? Compilation or? And does these libraries exist in the artifact?
What scope a lib has can be seen in the project settings modules/Dependencies wehre certain libs are connected to your project with a certain scope (provided, compile, test, runtime).
Whether or not the jar will be included in your artifact automatically, I'm not sure. Therefor best have a look at the project settings *artifacts/YOUR_ARTIFACT/output_layout* where your artifact is assabled. Look for warnings (lib missing or kinda stuff) then click through your artifact and search the folder WEB-INF/lib and its contents.
hth
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.