cannot run osgi bundles outside eclipse - java

I am making my firsts steps using osgi and I have a problem with a bundle I created.
I developed 3 bundles in eclipse (they are plugin projects). When I run my bundles inside eclipse using a new and empty target, they work very nice.
Then I tried to export them and run them without eclipse I ran with problems. I created a jar file for each one of them (using export ->deployable plugin) and then I install them in a running equinox container (v3.7.1, from eclipse's plugin directory) and I got a lot of ClassNotFoundExceptions for RuntimeErrorException
this looks like a classpath issue. I think I am not exporting the bundle correctly, but I am not sure.
The problem only happens with 2 of the bundles, which use additional libraries
how can I do it correctly?
In case you need it, this is the full stack

Taking one of the exceptions for example: NoClassDefFoundError on javax.management.RuntimeErrorException.
Did you import the package javax.management in your bundle?
See the following page from the OSGi Community Wiki, it seems directly relevant to your problem: http://wiki.osgi.org/wiki/Why_does_Eclipse_find_javax.swing_but_not_Felix%3F

Related

Package accessible from more than one module in Eclipse RCP

I updated an Eclipse RCP Project from Eclipse 2019-12 to 2020-03. After the update I get build errors on export, like the following:
"The package javax.xml.parsers is accessible from more than one module: , java.xml".
I am using Java 11, no module-info.java file, the Eclipse 3 Compatibility Layer and the eclipse product export wizard in my project.
The error message basically is clear to me. It detects some class twice on classpath, which is not allowed. Once the class is provided by JDK module "java.xml". The second copy comes from javax.xml osgi bundle.
My problem is that both of the packages can not be removed. The JDK module has a lot of dependent JDK modules that are actively used in code and I don't think that they can be supplemented by some libraries. The OSGI bundle is used by a lot of very basic eclipse bundles. So it can also not be removed.
So I have two questions:
Why does Eclipse RCP break projects with its new version? Was that considered a bug before? (I did not find a ticket)
How can I get my project to run again without really big changes?
Edit 1: Added reproducible example:
https://workupload.com/file/wKUZTXJXsR9
Edit 2: See also Eclipse Bug Ticket:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=562761
I created a minimum example. One can see the problem by exporting the product via wizard. I used DocumentBuilderFactory from javax.xml in Application.java to trigger the problem.
I found out a few things:
A plugin dependency to org.eclipse.help.ui is needed to trigger the problem. Although also other plugins have dependencies to javax.xml plugin.
Eclipse tells you the problem in Editor if I you add a direct dependency to javax.xml plugin. But we have only a transitive dependency to it and therefor get no hint.
That raises some new questions:
It seems that org.eclipse.help.ui plugin causes the problem, but we need it in our application. Is this a possible bug? Are there alternatives?
Why does eclipse editor not show the problem if I only have a transitive dependency to javax.xml plugin? Also a possible bug?
I found a workaround for this problem: When using a target definition (*.target file) instead of the Running Platform (automatic target definition of the Eclipse IDE) the error does simply not occur! I don't know exactly what the difference is between these two targets, since they both contain the "javax.xml" bundle. But when using the target file the "javax.xml" bundle is not added to the product file when automatically adding the dependencies and it does not complain later on that this bundle is needed "javax.xml". Somehow when using the target file the "javax.xml" is simply not needed and then no error occurs.
I think there is a bug in Eclipse RCP, that causes this problem when using the Running Platform. But I suggest using a target definition file anyways, since this brings a lot of other advantages.

Import JavaFX 11 Maven project to Eclipse

Is there any way to configure a Maven-based JavaFX project so that I can import the project in (vanilla) Eclipse and debug it like other Java/Maven projects?
I am used to distribute projects with Maven and typically, everyone in the team (as well as the CI server) can rely on Maven for packing, testing, running it etc.
For debugging, however, the project can be imported to Eclipse and started via a main class (as opposed to Eclipse's maven plugin).
A nice example is Spring-Boot. After importing such a project, I can just run or debug the main class.
For JavaFX 11 however, this seems to work to write a pom.xml that configures all necessary dependencies, but when I import such a project to Eclipse (as Maven project), it does not configure it to the point where I could run its main class. I can run "Debug as..Maven build..", but not via the main class. I understand that it depends on platform-specific dependencies, but if it can be started vie Maven, it should be possible to start it from Eclipse without configuring Eclipse, can't it?
I've been using Eclipse with a Maven project in exactly the way you would like to use it all the time with JFX11. It works without problems if you tweak the launch configuration correctly. Details can be found here: https://openjfx.io/openjfx-docs/
By far the easiest way to get this running is to ignore the module system and make sure that all libraries (also the JFX libraries) end up on the classpath and not the module path (which is the default if you do not have any module-info.java in your project). Then add a single line of code like this to the file with you main class.
class MyJFX11AppLauncher {public static void main(String[] args) {MyJFX11App.main(args);}}
In the Eclipse launch configuration make sure to launch your app via this new launcher class. That does the trick to run the JavaFX app without a whole flood of runtime options which you would need otherwise to get all this working. (See docs above.)
WARNING! This is not the official way to launch a JavaFX app but it works for me and I have never noticed any problem with it. Use at your own risk!

Eclipse classpath not showing IVY dependency tree. Is there a workaround?

For some reasons outside my control the project I am working on uses ivy.xml for buildtime dependencies and we have a separate runtime.xml ivy file for use when running up a service in eclipse. This is done by created a new runtime configuration and then adding the runtime.xml via the Advanced option on the Classpath tab of the launcher.
This works fine and the application runs up without any problems. The one major annoyance, is that having added runtime.xml the classpath view of the launch configuration just displays Ivy and does not provide a tree structure view like you get in the Project Explorer view (see screenshot below). This makes it impossible to quickly view the resolved dependencies for the runtime configuration.
We are on eclipse Kepler and I appreciate it is an older version, but was wondering whether:
There is a workaround?
This may have been rectified in a later version?

Launch configuration doesn't see classes from other bundles

I am writing an eclipse plugin with functionality distributed on some modules (core, util, ui etc). During implementing of new launch configuration (launch of course must call functionality from other bundles) for own project type I faced with the problem that this launch starts in new thread and a class that implements launch functionality don't see classes from other bundles and I have NoClassDefFaundError all the time.
I see that classes are loaded with different classloaders and this is OSGI specific behavior. I added necessary dependencies in MANIFEST files and eclipse shows me thats all ok and successfully build my plugins in workspace. But what happens wrong and why this doesn't work?
The problem is due to weird OSGi behavior on classloaders. Eclipse must ensure to have all classes within a single bundle packaged with PDE. So usually restarting IDE environment and rebooting your PC helps. The MANIFEST referring to das schlecht java code has to inject the dependency on a mojo class to the bundle activator. When you have several plugins built with Ant via Eclipse PDE it is unlikely that GI / PD Equinox can resolve the misusage of those. Am i right..or maybe there is another option which is to analyzed further.

automated osgi bundle development with netbeans 7.1

I'm currently developing a maven osgi bundle using Netbeans 7.1. While its easy to create new maven osgi bundle project from netbeans, I've been struggling about how I would run it. Simply running it from netbeans gives me an error that tells me there is missing requirement (missing slf4j for example).
Then I tried a different way. I ran equinox in a terminal and then manually install my project jar to it. But then I must also resolve all the dependencies manually.
Is there any way to automatically download all the required dependencies from an OSGI bundle and install it to a running OSGI framework?
thanx before
AFAIK there's no automation for OSGi in Netbeans (though I may well be wrong). The support you may have seen in Eclipse is only for Eclipse plugins not vanilla OSGi.
Your best bet is to go for some integrating testing or launch via a maven goal, pax-exam or bndtools or even pax-runner will allow you to launch from IDE/maven.
However I don't know of anything that will automatically resolve all dependencies (transitive dependencies and implementations of APIs you depend on would be problematic)
Its a big pain, no question about it. What I used to do was to do a full build (and if you've configured your manifests correctly should include all necessary dependencies) which will generate the necessary jar. I then wired my Tomcat to pick up the jar from my target repository and configured it to hotswap automatically.
Its a matter of preference if you want to run your app server from within your netbeans but I preferred to execute a separate instance of tomcat outside of my IDE. It'll work either way tho.

Categories

Resources