Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Maven - compiling against Equinox in Virgo 3.6.2.RELEASE(Using Maven as standalone (e.g. automated build) to build bundles for a Virgo target.)
Maven - compiling against Equinox in Virgo 3.6.2.RELEASE [message #1142864] Thu, 17 October 2013 22:31 Go to next message
Douglas Beattie is currently offline Douglas BeattieFriend
Messages: 6
Registered: October 2013
Junior Member
I'm using a standalone Maven project, and trying to declare dependencies for
the specific versions of Eclipse components distributed as the 'release'
version of Eclipse Virgo. However, I was not able to locate the exact
versions of the bundles in any public Maven repository. By inspecting the
META-INF/MANIFEST.MF of the include components, I was able to verify
the exact versions, and also conclude there is a consistent naming convention
which seems to be always {bundle-symbolic-name}_{bundle-version}. So, to
produce a standalone Maven project which can be built by a continuous-integration
tool or validated from scratch on a newly-provisioned build machine (without
the presence or necessity to manually load/compile a project from within
the Eclipse IDE), I arrived at some definitions which would build the project,
assuming the presence and availability of the required versions of dependency
artifacts from Equinox.

For example, here are the relevant definitions from the top-level POM file:

    <properties>
        <equinox.framework.version>3.8.1.v20120830-144521</equinox.framework.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>org.eclipse.osgi</artifactId>
                <version>${equinox.framework.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.eclipse.equinox</groupId>
                <artifactId>org.eclipse.equinox.cm</artifactId>
                <version>1.0.400.v20120319-2029</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.eclipse.osgi</groupId>
                <artifactId>org.eclipse.osgi.services</artifactId>
                <version>3.3.0.v20120307-2102</version>
                <scope>provided</scope>
            </dependency>
     ...


For example, looking at the 3rd dependency, installed as
virgo-tomcat-server-3.6.2.RELEASE/plugins/org.eclipse.osgi.services_3.3.0.v20120307-2102.jar

the dependency declaration is based on the contents of that POM file t the head of the source tree.

$ curl -s http://git.eclipse.org/c/equinox/rt.equinox.framework.git/plain/bundles/org.eclipse.osgi.services/pom.xml \
   | tail -n5 | egrep "<groupId>|<artifactId>|<version>"

  <groupId>org.eclipse.osgi</groupId>
  <artifactId>org.eclipse.osgi.services</artifactId>
  <version>3.4.0-SNAPSHOT</version>


Substituting the version number for our particular Bundle, which was provided in this release of Virgo:
  <version>3.3.0.v20120307-2102</version>


So, given these politically correct dependency declarations, the build will fail
because these specific versions are not available in a public repository. So, my
solution was to include the unpacking of a copy of Eclipse Virgo 3.6.2.RELEASE
on the build machine, at location '/opt/virgo-tomcat-server-3.6.2.RELEASE/',
and then manually add these dependencies to the machine-local Maven repository:

$ EXTJAR=/opt/virgo-tomcat-server-3.6.2.RELEASE/plugins/org.eclipse.osgi.services_3.3.0.v20120307-2102.jar
$ mvn install:install-file -Dfile=${EXTJAR} \
    -DgroupId=org.eclipse.osgi \
    -DartifactId=org.eclipse.osgi.services \
    -Dversion=3.3.0.v20120307-2102 \
    -Dpackaging=jar


Doing this for all Virgo components I wish to compile against (during development
of Virgo-specific bundles) produces a working standalone Maven build environment,
and I'm off and running.

So, my question now: is there a simpler or "better" way to achieve this?


. . .
Douglas Beattie
www.linkedin.com/in/beattidp

[Updated on: Tue, 29 October 2013 04:21]

Report message to a moderator

Re: Maven - compiling against Equinox in Virgo 3.6.2.RELEASE [message #1143425 is a reply to message #1142864] Fri, 18 October 2013 07:14 Go to previous messageGo to next message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 72
Registered: July 2009
Member
Hi,

If I am not mistaken, you should have all of your dependencies (including also the Virgo bundles' you depend upon) provided by a p2 repository and then tell tycho that the dependencies declared in your bundle MANIFEST.MF files are to be resolved by looking up bundles in that p2 repository.

Let me know If you need more details, and I'll try to have my build engineer involved in this discussion.

GianMaria.


Developing for Virgo using PDE: http://bit.ly/1w0tTit
Global JNDI in Virgo: http://bit.ly/1to42mn
Hyperic to monitor Virgo: http://bit.ly/W1Fst9
Profile Virgo with JProfiler http://bit.ly/1FBLGCw

[Updated on: Fri, 18 October 2013 07:15]

Report message to a moderator

Re: Maven - compiling against Equinox in Virgo 3.6.2.RELEASE [message #1149073 is a reply to message #1143425] Mon, 21 October 2013 23:11 Go to previous messageGo to next message
Douglas Beattie is currently offline Douglas BeattieFriend
Messages: 6
Registered: October 2013
Junior Member
With the recent uncertainty surrounding Virgo project leadership, my management asked me to evaluate a contingency plan, and I was forced to work with Apache ServiceMix for a couple weeks. Aside from breaking our app (mostly from Spring- and Gemini-related assumptions), the only thing I really liked about Karaf was the ability for dependencies to be pulled directly from a Maven repository -- which made sense, since there must usually be one there for development or build/deployment anyway.

The p2 repo and dependency-resolution problem is yet another subject (which I'd like to follow up, perhaps in a separate thread) which I also had to write a custom/interim solution for. So, yes it might be interesting to also have a build engineer involved in such a discussion in a separate thread.

This question is more of a build-time problem, as there seems to be limited means to compile against certain Equinox dependencies during a Maven-based build, outside of a manually-tended Eclipse IDE.


. . .
Douglas Beattie
www.linkedin.com/in/beattidp
Re: Maven - compiling against Equinox in Virgo 3.6.2.RELEASE [message #1151203 is a reply to message #1149073] Wed, 23 October 2013 07:33 Go to previous messageGo to next message
Florian Waibel is currently offline Florian WaibelFriend
Messages: 166
Registered: June 2010
Senior Member
Douglas Beattie wrote on Mon, 21 October 2013 19:11
..., the only thing I really liked about Karaf was the ability for dependencies to be pulled directly from a Maven repository -- which made sense, since there must usually be one there for development or build/deployment anyway.


I would like to see this functionality in a future release of Virgo, too.

Currently Virgo supports adding a Maven local repository[1]. Please raise an enhancement bug here and describe how you'd like to configure the remote Maven repository and how to specify the dependency in a plan for example.

[1] Add a Maven local repository - http://www.eclipse.org/virgo/documentation/virgo-documentation-3.6.2.RELEASE/docs/virgo-user-guide/htmlsingle/virgo-user-guide.html
Re: Maven - compiling against Equinox in Virgo 3.6.2.RELEASE [message #1151212 is a reply to message #1149073] Wed, 23 October 2013 07:37 Go to previous messageGo to next message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 72
Registered: July 2009
Member
Douglas Beattie wrote on Mon, 21 October 2013 19:11

This question is more of a build-time problem, as there seems to be limited means to compile against certain Equinox dependencies during a Maven-based build, outside of a manually-tended Eclipse IDE.


I was in fact referring to build-time. I suppose there is a misunderstanding, maybe originated by the fact that Virgo contains a p2 directory.

The p2 directory included in Virgo is used for provisioning Virgo itself which, as you know, comes in different flavours (Virgo Nano, Virgo Server for Apache Tomcat, etc), each of them obtained by installing via p2 additional optional components on top of the most basic distribution.

Since you were talking about Equinox bundles, I assumed that you are developing an OSGi application and that you use Virgo Server for Apache Tomcat. Since you cited Maven, I also assumed that you are using Maven/Tycho for building your application. Now, if all of the above assumptions hold, I confirm you can create a p2 repository used by Maven/Tycho to look-up you OSGi bundles dependencies (i.e. the dependencies declared in the MANIFEST as Import-Package or Require-Bundle). The repository should contain at the third-party bundles your application depends upon and typically also some or all of the bundles that Virgo makes visible to your application, which means the content of the Virgo repository folder and possibly also the Virgo plugins folder.

In this way, whenever Tycho is about to compile a bundle of yours, it will be able to compose the correct classpath by picking appropriate binary bundles from the p2 repository.

GianMaria.



Developing for Virgo using PDE: http://bit.ly/1w0tTit
Global JNDI in Virgo: http://bit.ly/1to42mn
Hyperic to monitor Virgo: http://bit.ly/W1Fst9
Profile Virgo with JProfiler http://bit.ly/1FBLGCw
Re: Maven - compiling against Equinox in Virgo 3.6.2.RELEASE [message #1159603 is a reply to message #1151212] Mon, 28 October 2013 16:56 Go to previous messageGo to next message
Harald Wellmann is currently offline Harald WellmannFriend
Messages: 34
Registered: July 2009
Location: Hamburg, Germany
Member
I don't think this answers the original question.

Building OSGi applications with Maven does not automatically mean working with Tycho and p2. (Eating your own dogfood is surely a good thing, but with Eclipse projects, I sometimes have the impression people forget that other projects out in the wild may have different and incompatible standards.)

Mixing POM-first and manifest-first approaches is not trivial.

For projects having lots of dependencies in Maven repositories (not p2) and using maven-bundle-plugin to generate OSGi manifests, it would indeed be very convenient to have all Virgo bundles and their transitive dependencies in a Maven repository, preferably in Maven Central.
Re: Maven - compiling against Equinox in Virgo 3.6.2.RELEASE [message #1160327 is a reply to message #1159603] Tue, 29 October 2013 04:17 Go to previous message
Douglas Beattie is currently offline Douglas BeattieFriend
Messages: 6
Registered: October 2013
Junior Member
Just to confirm: my project utilizes only the 'maven-bundle-plugin'. I do not use Tycho plugins, nor have I evaluated them in depth, as they appeared to be less stable, with limited documentation, and still seem to be evolving; nor do I use the bundlor, since it seemed less-capable than the maven-bundle-plugin.

The basic declaration is in my top-level POM (which is of packaging type 'pom', and serves as the parent for 7 modules so far).

<build>
  <pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>${maven.bundle.plugin.version}</version>
            <extensions>true</extensions>
            <configuration>
                <obrRepository>obr/repository.xml</obrRepository>
                <instructions>
                    <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Name>${project.name}</Bundle-Name>
                    <Bundle-Version>${project.version}</Bundle-Version>
                    <Bundle-ClassPath>.</Bundle-ClassPath>
                    <Export-Package>
                        ${project.groupId}.${project.artifactId}
                    </Export-Package>
                </instructions>
            </configuration>
            <executions>
                <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                    <configuration>
                        <manifestLocation>src/main/resources/META-INF/</manifestLocation>
                    </configuration>
                </execution>
            </executions>
        </plugin>

All modules inherit the baseline plugin configuration, and can further tune or override the declarations given under 'pluginManagement' in the parent POM. A module can then simply declare something as simple as:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <!-- version managed by parent POM -->
            </plugin>
        </plugins>


In practice, this is working pretty well for me, with the bundle manifests containing plenty of versioned imports which correspond to each module's declared dependency versions.

And yes, the target is Virgo Server for Apache Tomcat. It has been fun so far, and useful to follow the logs, check the status of bundles and resources, and even adjust log levels on the fly for troubleshooting and verification purposes. My manager was pretty impressed as well.



. . .
Douglas Beattie
www.linkedin.com/in/beattidp

[Updated on: Tue, 29 October 2013 04:22]

Report message to a moderator

Previous Topic:Spring MVC with blueprint
Next Topic:Running Virgo as a lightweight container with Docker
Goto Forum:
  


Current Time: Thu Mar 28 16:22:27 GMT 2024

Powered by FUDForum. Page generated in 0.07052 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top