osgi with eclipse maven and maven-bundle-plugin - eclipse

I'm new to osgi and really confused about how it all fits together. I want to create 3 bundles, an api bundle that defines an interface, a impl bundle that provides an implementation and another bundle that uses the implemenation using maven and the maven-bundle-pugin.
I need a bit of guidance:
do i need 3 maven projects?
does it help to/should i use a maven archetype for creating the projects?
do i need tu use maven-pax?
any other hints for a osgi newbie?
Thank you

I have written a tutorial some time ago that may contain what you need.
Some spoilers ..
Yes you should create three maven projects. Ideally also a parent project so you can build them in one command.
You can use an archetype but the easier way may be to just copy the example code and change it.
The tutorial shows how to deploy on Apache Karaf which imho is the easiest OSGi server to start with. Still the bundles produces during the build should also work in plain Felix or Equinox but the deployment will be a little harder.

Related

How to add java source code for AspectJ in eclipse

I am learning AOP with Spring framework and I want to set the javadoc for AOP in eclipse. So what I did I downloaded aspectj-1.8.10.jar from eclipse web site https://eclipse.org/aspectj/downloads.php#install then I installed that jar and got 4 new jar files: aspectjrt.jar, aspectjtools.jar, aspectjweaver.jar, org.aspectj.matcher.jar which I added to my class path in eclipse. Now what I want is to add source files for these jars so, for example, when I hover over #Aspect I want to be able to see what this annotation represents. Unfortunately I can not find the source files for these jars, on the eclipse website mentioned above there is a file aspectj-1.8.10-src.jar but I'm not sure what to do with it, I tried to attach this file directly in the build path for each of the jars mentioned above but it didn't do the trick. Also I thought that maybe I had to install aspectj-1.8.10-src.jar the way I installed aspectj-1.8.10.jar so I would get 4 source files, but I'm not sure how (if possible) to install it, when I double click aspectj-1.8.10-src.jar, installation does not get triggered.
So can you please help me out to add javadoc for AspectJ 1.8.10 in Eclipse?
Select the library in your Eclipse project explorer window, click right button, select properties, select javasource attachment or javadoc location and enter the path to the source or javadoc file.
But I would suggest to use maven to maintain the dependencies of your project. It makes getting javadoc much easier, because libraries, source code and javadoc are fetch from a central repository. You just add the library you need in your project configuration (pom.xml file) and the other files are fetched for you.
You do not need all those libraries. Please first learn which one serves which purpose. E.g. aspectjrt is the runtime. When using Spring AOP you actually do not really use AspectJ, only a subset of its syntax. Thus, the runtime is needed for identifying some of the annotation classes. However, aspectjweaver is only needed if you want to use full AspectJ in a load-time weaving (LTW) scenario, with or without Spring. The weaver lib is a superset of the runtime, so you only need one of them. Last, but not least, aspectjtools again is a superset of the weaver lib and contains the AspectJ compiler (among other tools). This is only needed for compile-time weaving as part of your toolchain.
I do not think that source code and Javadoc will help you much in learning AspectJ. I suggest you read the Spring manual's AOP chapter describing both proxy-based Spring AOP and full AspectJ integration via LTW. If you want to learn AspectJ basics and maybe just use AspectJ without Spring (which is what I do), read the AspectJ documentation.
If you are still not convinced and want to add source and JavaDoc to your Eclipse project, why don't you follow jaysee's advice and use Maven? Then you get all the source/javadoc libs for free. But anyway, you can also load those JARs directly from Maven Central, e.g. the source and javadoc for AspectJ runtime 1.8.10. Good luck! But I assume you will be disappointed because the AspectJ JavaDoc is really bad for learning purposes and not suited to understanding how to actually use AspectJ.

Working modular example for JavaFx8 + OSGi + Gradle multiproject without additional tooling?

I am stuck with a problem I can't solve for weaks now.
I have to create a modular JavaFX application, where each component defines a "domain unit" (with models+views+controllers). Each component can be loaded into a "shell application" (as a content of a tab view or multiple tab views) and the modules can depend on another module(s) (their content in tabs won't appear if their dependency is not loaded).
That's why I was planning to create an OSGi based JavaFX application and build it with Gradle as a multiproject.
I've already tried dozens of tutorials with no success and I experienced, that most of these tutorials:
are outdated, not reproducible (e.g. elcipse's interface, templates have changed, bndtools tutorials doesn't seem to work, equinox doesn't seem to to work without felix, javafx8+osgi generate different kind of problems... etc.)
are too complex for a beginner (I just started to learn OSGi and Gradle) and they skip important steps I am not aware of
contain too much "IDE magic" (I would rather type some code instead of filling forms in eclipse)
some solve the problem with different tools (maven/tycho, bndtools, e(fx)clipse), but I've got no time to learn them
I want my application to be independent from IDE's environment. I don't want to use e(fx)clipse or BndTools if possible (even if they can make the build process easier)..
I'm experimenting with OSGi implementations, that's why I would rather not to choose between Equinox, Felix or Karaf.
I've already programmed similar application in .NET world, but it seems to me impossible to do the same in Java world..
My main questions are:
is it possible to do what I have imagined?
how to create a gradle multiproject what is IDE/platform independent (if projects are not tied to eclipse environment, or equinox, but it's possible to use them)?
what are the best ways to initialize the application (shell application + modules) and load the independent modules/bundles/components?
how to separate my views into subprojects (what build.gradle files should contain)?
how to solve the javafx8 inpompatibility with osgi?
what is the correct way to apply javafx plugin in gradle?
what tutorials are the most relevant?
is there any working example, pattern or tutorial (without using additional tools) what solve the same problem (using only osgi+javafx+gradle)?
I could group your questions in differents topic:
OSGI
You just need to google around to find out that is a java specification that encourages modularization, provides hot-deploy feature, and so on. As I told you, is just an specification like Java Servlet API, so they are different providers or implementers of OSGI Specification such as Felix and Equinox. Karaf instead is a OSGI container based on Felix, so you get all felix benefits and in addiction karaf natives features. For that reason I encourage you to take Karaf into use.
Aquote BndTool
In order to satisfy the OSGI specification, you need that your modules contains a MANIFEST.MF which holds all dependency information so Karaf create the classloader required for your bundles.
Assuming that you don't want to create that MANIFEST.MF files by hand, you could take aqute/bndtool for that. Don't get mess with bndtool for eclipse plugin. That application can be used from command line, from a maven plugin, or from a gradle plugin. Basically scans your classes, check the imports, and create a MANIFEST.MF automatically.
Gradle
If you choose gradle as a build tool, then you can take into use: Bnd Gradle plugin. It's easy to set up, but follow the instruction for non-workspace plugin. If you don't want to use BndTool for eclipse. IDE independent solution, you mentioned in your question.
MultiProject Layout
How the project layout should look like, depends on your modularization, but you can have a look on this layout example that uses gradle+osgi+karaf for a multiproject. Perhaps inspires you.
https://github.com/antoniomaria/gradle-karaf-bnd-project

OSGI bundle - Eclipse project bundling with ALL dependencies

I am new to the OSGI world and could use some advice from the experts out there. My aim is to deploy a few servlets along with REST resources into a standard Karaf installation. I am planning to use Grizzly (w/Jersey) as the http container.
I am trying to figure out a way to create an eclipse project, in which I can compile my custom code, and deploy this code along with all dependencies such as Grizzly, Jersey, OSGI frameworks & bundles as a single archive into Karaf.
The end goal is to have a single deployable entity which includes all my code and the dependencies without needing to manually install dependencies in Karaf.
Is this possible or am I looking at it the wrong way? I have been reading up on OBR, features and KAR but not able to put the whole picture together as yet. What would be the best practice wrt achieving this objective?
Thanks!
To give you the general idea regarding embedding and launching a complete OSGi application, I suggest you check out chapter 13 on this book. It explains it using Equinox implementation but I hope the overall approach should look similar. If you follow through you will see that you can put all your bundles in a folder where the system will iterate through and install them.

Dynamic web application in eclipse using MAVEN 3.04

From past 90 hours I am trying to know how to use Maven in my web project, generate a war file and deploy it into my JBoss 4.2 Server.
I am not getting.
I am reading all kinds of blogs, googling almost all time, trying out all kinds of way to build a dynamic web project with maven, but trying out different methods make a simple thing more complex.
Few examples tell me how to run, few tell me to change the folder structure, few tell me transfer the contents of web content but nothing is matching my requirements. In some of the examples war file is getting generated, but of some big name, and it does not contain the jars inside. Uff.
I know maven is easy and makes our lives better but learning it for the first time makes it complex.
My requirement is simple.
1) Build a Dynamic web project in eclipse indigo. (Preferably in JAVA perspective )
2) Enable Maven dependencies, in eclipse.
3) Update pom.xml to add dependencies.
4) Finish the web application i want to do by writing classes, html pages, deployment descriptors.
5) Build the war file using maven "IN ECLIPSE ONLY". (the WAR file must have user specific name and not some name like "V1- Snapshot dash dash dash")
6) Deploy my war file in jboss 4.2 server deployment location. (Preferably from eclipse )
7) Run my localhost server and my application from the browser.
And Done.
By spending time on it I am understanding how beautiful is maven, but I am not able to achieve what I want.
Please help me by giving me a detailed procedure on how to use maven to meet my requirements above.
Fist I would suggest to use the newest Eclipse (Juno) with Maven support (m2e and wtp-m2e).
The first step is to define your pom with the appropriate dependencies and the correct packaging type which is in your case war.
If you really need a different naming you should leave Maven, cause maven makes assumptions about the naming of your artifacts which usually isn't a problem. The default version patterns as 1.0.0-SNAPSHOT etc.
If you wan't to deploy the war into JBoss there exist a number of possibilites to do such things and if you like to run your application locally it sounds you wan't to do some kind of testing (integration testing) which is supported by Maven (see maven-failsafe-plugin).
Furthermore you must learn if you like to use Maven to understand that not Eclipse is anymore the leader of the project configuration. This job has been moved to Maven or in other words into the pom file. If you like to use the project in Eclipse you need to import this project into Eclipse.
Apart from the above i would suggest to go to a Maven training to lear all that stuff which is more effective than learning it yourself.

Exporting Eclipse RAP war with OSGi bundles with external bundle-path

I have an Eclipse RAP product, I like to export as a web app for use inside Tomcat. For this I use the warproduct exporter in Eclipse, which until now have worked fine.
I have a problem with compilation of one of the OSGi bundles in the product as this refers to a set of external jars using a variable substitution. This is shown in the following fragment from a MANIFEST.MF:
Bundle-Name: ...
Bundle-SymbolicName: ...
Bundle-ClassPath2: external:/A/test1/jakarta-tomcat/shared/lib/a_base.jar
Bundle-ClassPath: external:$A_HOME$/jakarta-tomcat/shared/lib/a_base.jar
If I use the first classpath instead and have the correct /A/test1/jakarta-tomcat/shared/lib/a_base.jar in place, then everything is fine during the compilation... And I can even manually change the MANIFEST.MF afterwards to the correct version with the substitution.
But, I would really like to avoid this extra step, if at all possible!
I think the question is how to pass in a proper value for A_HOME during the compilation?
(Why do this? Above, I just shown a single jar file, but we have a larger number of jar files we want to share between our older Tomcat applications and the newer RAP based application. We know, there are other ways of sharing jars in this situation - e.g. via an OSGi framework extender or the extendedFrameworkExports initialization parameter in web.xml - but we need the chosen method as we use EMF and therefore cannot share the EMF meta data between Tomcat and Eclipse... And thus not the class objects...)
this feature is currently not support within the WAR Products Tooling. I recommend to open a bug against Eclipse Libra and to define the feature request their. Anyway, we have created an example how to build a RAP application with tycho which is pretty easy, maybe you want to take a look: https://github.com/eclipsesource/rap-mobile-demos
Cheers Holger