Between the Times
This week is (supposed to be) “quiet week” at Eclipse: Release Candidate 4 is in place and more testing is being done before the final Indigo Release. Time to speak of s.t. that the Object Teams project has neglected a bit in the past: compiling / building with Maven.
Compiling OT/J with Maven
In the days of Maven2, pluging-in a non-standard compiler required fiddling with the nexus compiler plugin, which was buggy and all that. With the recent development around Maven3 and Tycho things became easier. The following pom-snippet is all you need to tell Maven to use the OT/J compiler:
<build> <pluginManagement> <plugins> <plugin> <!-- Use compiler plugin with tycho as the adapter to the OT/J compiler. --> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <compilerId>jdt</compilerId> </configuration> <dependencies> <!-- This dependency provides the implementation of compiler "jdt": --> <dependency> <groupId>org.sonatype.tycho</groupId> <artifactId>tycho-compiler-jdt</artifactId> <version>${tycho.version}</version> <exclusions> <!-- Exclude the original JDT/Core to be replaced by the OT/J variant: --> <exclusion> <groupId>org.sonatype.tycho</groupId> <artifactId>org.eclipse.jdt.core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <!-- plug the OT/J compiler into the tycho-compiler-jdt plug-in: --> <groupId>org.eclipse</groupId> <artifactId>objectteams-otj-compiler</artifactId> <version>${otj.version}</version> </dependency> </dependencies> </plugin> </plugins> </pluginManagement> </build>
This relies on the fact, that the OT/J compiler is compatible with the JDT compiler, good.
To make things go smooth in various build phases a few more bits are required:
- provide the OT/J runtime jar and its dependency (bcel)
- tell surefire about required command line arguments for running OT/J programs
These basics are collected in a parent pom so that all you need are these two snippets:
<repositories> <repository> <id>ObjectTeamsRepository</id> <name>Object Teams Repository</name> <url>http://download.eclipse.org/objectteams/maven/3/repository</url> </repository> </repositories> <parent> <groupId>org.eclipse</groupId> <artifactId>objectteams-parent-pom</artifactId> <version>2.0.0</version> </parent>
This converts any Java project into an OT/J project, simply enough, huh?
At least compiling and testing works out-of-the box. Let me know what additional sophistication you need and if adjustments to other build phases are needed.
OT/J over m2e
Well, I’m not much of a Maven expert, but I’m an Eclipse enthusiast, so, how can we use the above inside the IDE?
The bad news: the m2e plug-in has hardcoded its support for the compiler plugin to use “javac” as the compiler. Naive attempts to use tycho-compiler-jdt have failed with the infamous "Plugin execution not covered by lifecycle configuration".
The good news: By writing a tiny OT/Equinox plug-in I was able to remedy those issues. If you have the m2e plug-in installed (Indigo version), the normal “Update Project Configuration” action will suffice:

After that, the project is recognized as an OT/J project, both by the IDE …

… and also by maven …

Where to get it?
The mentioned plug-in is brand-new and as such it is not part of the regular OTDT distribution. OTOH, the plug-in is so simple, I don’t expect a lot of changes needed. So, if you have an Indigo-ish Eclipse just add this update site:
Then install “Maven Integration for Object Teams (Early Access)”:

Don’t forget the <repository> and <parent> definitions from above and you should be ready to go! Yesss, sometimes it pays off that OT/J is a kind of Java, a lot of the tooling can just piggy-back on what’s already there for Java


Hi Stephan,
Is it possible to use OTDT with AJDT?
Right now I see a lot of exception but I’m not sure what’s the cause:
{{{
at org.eclipse.ui.application.WorkbenchAdvisor$1.run(WorkbenchAdvisor.java:781)
Caused by: org.osgi.framework.BundleException: The activator org.eclipse.jdt.core.JavaCore for bundle org.eclipse.jdt.core is invalid
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:171)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:268)
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
… 66 more
Caused by: java.lang.ClassFormatError: Duplicate field name&signature in class file org/eclipse/jdt/core/JavaCore
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:601)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:567)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:490)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassName(ClasspathManager.java:469)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:456)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:476)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:164)
… 72 more
}}}
ilx
4 Jul 11 at 12:11 pm
Hi Ivica,
During the last months our focus was on compatibility with other tools that are part of the Indigo Simultaneous Release. Since AJDT is not part of Indigo this issue had lower priority, but we are aware that potentially the combination of both weavers could cause havoc as your stack trace signifies.
I’ve opened bug 351085 to track the issue, so if you have more information please add them to the bug.
On a side note: are you using AspectJ and OT/J within the same project, or is it just for different projects within the same workspace? Naturally, I wouldn’t expect you to *need* AspectJ if you already have OT/J
best,
Stephan
stephan
4 Jul 11 at 2:19 pm
I’ve uploaded a 2.1.0-SNAPSHOT version of the above, that:
- uses tycho 0.14.1 (org.eclipse.tycho namespace)
- includes OT 2.1 M6 binaries (compiler&runtime)
To upgrade simply change the parent-pom version.
stephan
3 Apr 12 at 11:34 pm
[...] a previous post I showed how the tycho-compiler-jdt Maven plug-in can be used for compiling OT/J code with [...]
Compiling OT/Equinox projects using Tycho at The Object Teams Blog
31 Oct 12 at 12:16 am