Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

OTHowtos/BuildTime Weaver

While load-time weaving has the advantage of easier deployment - no tweaking of the classpath is required to ensure that the right version of a class is loaded - it may be difficult to integrate in some application containers. As a fallback mechanism, the OT weaver can be used to process all affected classes already at build-time. The resulting woven classes can then be executed on any JVM (≥1.5) without using the load-time weaver.

objectteams-weaver-maven-plugin

Currently, the built-time weaver only exists as a Maven plugin. If you'd like to use it without Maven, please file a bug

Maven site
http://download.eclipse.org/objectteams/maven/3/sites/objectteams-weaver-maven-plugin

The Usage page already explains the basics, so let's directly go to some examples:

Stopwatch

The stopwatch example has always been the OT/J hello world, so how would this be configured to work without the load-time weaver?

Download
http://download.eclipse.org/objectteams/examples/maven/OTStopwatch_Built-Time_Weaver_Example.zip


Unpack this zip in a fresh directory and inspect the pom.xml:

  • parent: configure the project for compiling OT/J code
  • properties: select tool versions:
    • tycho is used for integrating the OT/J compiler for Maven
    • OT/J version 2.2.0 corresponds to the Kepler release
  • repository: tell maven where to find any Object Teams artifacts and plug-ins
  • dependencies: tell maven that we need the OT/J runtime library. In fact only a small portion is needed since we don't use the load-time weaver
  • plugin objectteams-weaver-maven-plugin: this is the main configuration item
    • activate goal weave
    • specify which team classes should be processed by the weaver. Additional classes will be automatically pulled in as needed.

For a hello world examples this is all. See the Usage for all configuration options of this plugin.

When you're ready just say:

mvn install

You should see within the maven output:

[INFO] --- objectteams-weaver-maven-plugin:0.8.0-SNAPSHOT:weave (default) @ OTStopwatch_Built-Time_Weaver_Example ---
[INFO] ==== Scanning OT classes ====
[INFO] Scanning OT class: org/eclipse/objectteams/example/stopwatch/WatchUI.class
[INFO] Scanning OT class: org/eclipse/objectteams/example/stopwatch/WatchUIAnalog.class
[INFO] Scanning OT class: org/eclipse/objectteams/example/stopwatch/WatchUI$__OT__WatchDisplay.class
[INFO] Scanning OT class: org/eclipse/objectteams/example/stopwatch/WatchUIAnalog$__OT__WatchDisplay.class
[INFO] Scanning OT class: org/eclipse/objectteams/example/stopwatch/WatchUIAnalog$WatchDisplay.class
[INFO] Scanning OT class: org/eclipse/objectteams/example/stopwatch/WatchUI$WatchDisplay.class
[INFO] ==== Weaving teams ====
[INFO] ==== Weaving other classes ====
[INFO] ==== Number of woven classes: 7 ====
If you don't see this you may peek into the #Troubleshooting section, but gee wiz, I'm probably the wrong person to ask when Maven has a bad day...

After BUILD SUCCESS you may want to have a look into target/woven-classes, where you'll find the result of weaving. If you package the content of this directory, you should be ready to run this OT/J program in every Java environment.

Now, as mentioned, we need to be careful to provide the correct classpath in the correct order. So here is what you could say on Linux:

java -classpath target/woven-classes:\
target/classes:\
${HOME}/.m2/repository/org/eclipse/objectteams/objectteams-runtime/2.2.0/objectteams-runtime-2.2.0.jar \
org.eclipse.objectteams.example.stopwatch.Main
  • first entry is target/woven-classes to override non-woven versions
  • target/classes is still needed for classes not affected by weaving
  • objectteams-runtime-2.2.0 is needed just for a handful of classes like org.objectteams.Team, the ancestor of all team classes


Troubleshooting

  • When I built the Stopwatch example for the umptieth time Maven finally greeted me with:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project OTStopwatch_Built-Time_Weaver_Example: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile: java.lang.NoSuchMethodError: org.codehaus.plexus.compiler.CompilerConfiguration.getProc()Ljava/lang/String;
  • Isn't that what we all love maven for? I'm unable to say, what causes the same project to succeed and then fail on the same machine.
  • Anyway, what Maven is trying to tell you is that it wasn't able to make up its mind about which version of maven-compiler-plugin to use. The fact is: I don't care and I didn't mention any version number, so Maven is free to make any choice that it likes. But sometimes it makes a choice which it doesn't like.
  • For me the only way out of this was specifying a pluginManagement stanza (inside <build>):
       <pluginManagement>
           <plugins>
               <plugin>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>2.3.2</version>
               </plugin>
           </plugins>
       </pluginManagement>
  • don't ask any questions

Back to the top