new: I've tried now Tycho times, so that everything is better:) But I do
for a new tutorial that Mattias Holmqvist ( Part 1, Part 2 and part 3) is already pretty perfect. My Experiences that I have described under build OSGi bundles with Tycho .
---
age post (caution, I have broken's upper and lower case and cleaning up worth of top Description reason is no longer) was to build
OSGi bundles and Eclipse plug-ins have always been very cumbersome and error-prone . This brings me even to the attitude that I would rather avoid OSGi. In particular, it does so as a rule, no business value. Changing the subject, I am sometimes forced by the environment to build plugins for the Eclipse Rich Client Platform.
My conditions are as follows: I would like to develop in Eclipse and also there all possibilities to use the PDE. On the other hand, it is to be exported for me no option bundles finished by a developer from its IDE. I use anyway, namely an automatic build system (after all, I am not alone in the world, but cooperating with other, spread some seated colleagues) to do to Continuous builds and nightly builds (see my last post). There I would like to build bundles of Maven. So far we have done here in the company of the automated PDE build, the process is very cumbersome and error-prone.
bnd The tool and maven-bundle-plugin from the Apache Felix project but is now an exciting and usable option. Exciting because bnd is a completely new way - namely, it is not based (only) on declarations, but analyzed the compiled code to discover dependencies, and entered in the MANIFEST.MF.
Now the solution: I use not only a bundle, I have a "common-pom.xml" as a common parent POM my bundle projects.
where I use the following entry under Plugins:
\u0026lt;plugin>
\u0026lt;groupId> org.apache.felix \u0026lt;/ groupid>
\u0026lt;artifactId> maven-bundle- plugin \u0026lt;/ artifactId>
\u0026lt;extensions> true \u0026lt;/ extensions>
\u0026lt;configuration>
\u0026lt;manifestlocation> META-INF \u0026lt;/ manifestlocation>
\u0026lt;instructions>
pom.groupId \u0026lt;bundle-symbolicname> $ {.}} $ {pom.artifactId; singleton: = true \u0026lt;/ Bundle-symbolicname>
bundle.activator \u0026lt;bundle-activator> $ {} \u0026lt;/ bundle-activator>
\u0026lt;embed-dependency> *; scope = compile
\u0026lt;/ instructions>
\u0026lt;/ configuration>
\u0026lt;/ plugin>
The necessary properties I've defined in the parent-POM as follows:
\u0026lt;properties>
\u0026lt;bundle.activator> pom.groupId $ {}. pom.artifactId $ {}. internal.Activator \u0026lt;/ bundle.activator>
\u0026lt;bundle.import- packages> \u0026lt;/ bundle.import-packages>
\u0026lt;/ properties>
for the interaction with the Eclipse IDE, achieved thanks to a number of entries: First, I use as ManifestLocation of course the "default" path of Eclipse (META-INF), not the maven-default target as.
Secondly, I use an "Embed-Directory" (lib), which I'm using maven-dependency-plugin all the necessary dependencies (ie 3rd party libraries that I do not convert to OSGi bundles) copy. The relevant section of the Parent-POM is as follows:
\u0026lt;profiles>
\u0026lt;profile>
\u0026lt;id> eclipse \u0026lt;/ id>
\u0026lt;build>
\u0026lt;plugins>
\u0026lt;plugin> ;
\u0026lt;artifactid> maven-clean-plugin \u0026lt;/ artifactid>
\u0026lt;executions>
\u0026lt;execution>
\u0026lt;id> clean-eclipse-dependencies \u0026lt;/ id>
\u0026lt;phase> process-resources \u0026lt;/ phase>
\u0026lt;goals>
\u0026lt;goal> clean \u0026lt;/ goal>
\u0026lt;/ goals>
\u0026lt;configuration>
\u0026lt;filesets>
; \u0026lt;fileset>
\u0026lt;directory> $ {basedir} / lib \u0026lt;/ directory>
\u0026lt;includes>
\u0026lt;include> ** / * \u0026lt;/ include>
\u0026lt; / includes>
\u0026lt;/ fileset>
; \u0026lt;/ filesets>
; \u0026lt;/ configuration>
\u0026lt;/ execution>
; \u0026lt;/ executions>
\u0026lt;/ plugin>
\u0026lt;plugin>
\u0026lt;artifactid> maven-dependency-plugin \u0026lt;/ artifactid>
\u0026lt;executions>
\u0026lt;execution>
\u0026lt;id> copy-eclipse-dependencies \u0026lt;/ id>
\u0026lt;phase> process-resources \u0026lt;/ phase>
; \u0026lt;goals>
\u0026lt;goal> copy-dependencies \u0026lt;/ goal>
\u0026lt;/ goals>
; \u0026lt;configuration>
\u0026lt;outputdirectory> $ {basedir} / lib \u0026lt;/ outputdirectory>
\u0026lt;includescope> compile \u0026lt;/ includescope>
; \u0026lt;includescope> runtime \u0026lt;/ includescope>
; \u0026lt;excludetypes> pom \u0026lt;/ excludetypes>
\u0026lt;/ configuration>
; \u0026lt;/ execution>
\u0026lt;/ executions>
; \u0026lt;/ plugin>
\u0026lt;/ plugins>
\u0026lt;/ build>
\u0026lt;/ profile>
...
\u0026lt;/ profiles>
For a concrete bundle are now "only" relatively few steps required:
course, the project must reference the parent-POM accordingly (I do this with me by relative-path as follows) :
\u0026lt;parent>
\u0026lt;groupId> de.vizmind \u0026lt;/ groupid>
\u0026lt;artifactId> \u0026lt;/ id>
\u0026lt;version> 0.0.1-SNAPSHOT \u0026lt;/ version>
\u0026lt;relativepath> .. / de.vizmind.common / use
\u0026lt;/ parent>
pom.xml as packaging has to bundle:
\u0026lt;packaging> bundle \u0026lt;/ packaging>
Now you can just as usual, enter its Dependencies, with the compile and are runtime dependencies as mentioned above copied to the lib folder and so on the mechanism of Eclipse PDE can be used - this fact has its problems with the "Maven Dependencies" of the m2eclipse plugin.
dependencies to other bundles is marked simply with the scope "provided", which are then used to justify the "import-packages" to determine, but not copied into the bundle.
Now it may be necessary nor the properties of the parent-POM "to define, for example, if one has not defined a Activator (the default is under internal.Activator
pom.groupId $ {}. Pom.artifactId $ {}.
expected). If one has to define dependencies, which do not arise from the class files, then the manually to do on the property "bundle.import-packages". Since this property is simply hung from the automatically determined, you have to finish it (yet) with a comma if it is not empty. (Another point for improvement). In our example we use here in a bundle jumping in and reference the context.xml a PropertyPlaceholderConfigurer. The import of this class can not of course automatically. Class files are determined, so it must be added manually. (Another point for improvement - Automatic Analysis of Spring-files).
Together this will look as follows from:
\u0026lt;properties>
\u0026lt;bundle.activator> \u0026lt;/ bundle.activator>
\u0026lt;bundle.import-packages> org.springframework.beans.factory.config, \u0026lt;/ bundle.import-packages>
\u0026lt;- Close with "," if you have a non-empty list ->
\u0026lt;/ properties>
is now my project finished. The use of a profile (in the parent-POM, see above) ensures that I can create the following Maven command an Eclipse project without the proper build later to get in your way.
mvn eclipse: clean eclipse: m2eclipse process-resources compiler: compile bundle: manifest Declipse.pde = true Peclipse
The project can now be imported into Eclipse. The only problem: Currently the classpath-file is not structured so that the embedded 3rd party libraries are also referenced.. The record must be once more "by hand" in the build path.
The command is a bit cumbersome, perhaps later here I am doing a little "fine tuning". For now it works for now.
The way is thus free to use the bundle in the Eclipse IDE and develop.
With
mvn package
you can now build the bundle also, so that even the automated build no more obstacles.
Ciao
Chris
0 comments:
Post a Comment