SlideShare a Scribd company logo
Moving from   to
Why move?
●   Plexus is not widely used outside of Maven

●   Lack of documentation, not always up-to-date

●   Extra steps needed to generate Plexus XML

●   Not type-safe, lacks support for generics
●   Single plexus.xml




●   META-INF/plexus/components.xml (Class-Path)
●   Has annotations, but still need to generate XML
Why               ?
●   Standard:   reference implementation for JSR 330

●   Flexible:   can map all sorts of metadata to bindings

●   Type-safe: detailed messages when things go wrong

●   Modular:    multiple extensions available, OSGi-ready
JSR 330
●   New standard for Java dependency injection


                                    // Constructor injection


               // Field injection




                                     // Setter injection
●   Fluent Java binding API




●   Records generic information lost during erasure

●   Can be driven by Java / annotations / XML / ...etc...
Migration Path
●   Preserve investment in legacy Plexus components
●   Allow gradual migration to JSR 330 annotations




●   Must support mixture of Plexus and JSR 330
Customizing
●   Guice provides an SPI to hook into injections

    ●   TypeListeners called for matching bound types
    ●   Register MembersListeners for custom injection
    ●   Register InjectionListeners for custom lifecycles

●   SPI supports binding introspection / rewriting
Injection Listeners
-y Beans
●   Writing all those listener classes can get tedious
●
    guice-bean library cuts out most of the work

    ●   You provide a BeanBinder implementation
    ●   that can provide PropertyBinders for each type
    ●   which can supply PropertyBindings for each property

●   Bean conventions select field / setter properties
Compatibility Shim
Metadata
●   Canonical form of Plexus bindings

●   Captures @Component implementations
●




●   Maps @Component bean properties to

    ●   @Requirement settings
    ●   @Configuration settings

●   Interns Plexus hint strings to save space
Scanning for                   Metadata
●   ClassSpace abstraction supplies classes / resources

●   Can be backed by Plexus Classworlds or OSGi

●   Plexus XML mapped into Plexus annotations

●   Plexus annotations are interpolated and stored
Converting                    Configuration
●   Builds on top of standard Guice TypeConverters




●   Supports properties, nested collections, and beans
●   Guice SPI lets you add your own TypeConverters
Locating                 Components
●   Guice bindings map Keys to Providers
●   Each Key has a type and optional annotation
●   Plexus components have roles and hints


    Key == Class<Role> + @Named(hint)

●   Uses Guice SPI to find component bindings
Binding                  Components
●   Opposite of locating components

●   @Component roles and hints turned into Keys

●   Keys used to bind component implementations

●   Singleton default, unless strategy is "per-lookup"
Injecting                 Requirements
●   @Requirement           locate Plexus components

●   Handles Maps, Lists, instances, and Wildcards

●   Loggers automatically configured and injected

●   @Configuration          convert constant using type
Managing                    Lifecycles
●   Uses an InjectionListener to listen for bean instances

●   Plexus lifecycle "personality" applied after injection

●   Reverse lifecycle applied when container disposed

●   Need to manage extra metadata (like descriptions)
Time for a Demonstration!
Classworlds
●   Plexus Container API still depends on Classworlds

●   But dependency is much less in guice-plexus-shim

●   Just need to write classworlds-shim around OSGi

●   ... to get Plexus apps running on OSGi containers
Extending JSR 330
●   JSR 330 tells us how to mark dependencies



●   and qualify them (just like with Plexus hints)



●   But it does not say how to mark components
Identifying JSR 330 components
●   Wrap the Class-Path up as a ClassSpace and scan it
●   Look for classes with qualifiers such as @Named




●   Empty @Named means "use class name" instead
●   Binding type found by analysing class hierarchy
Next Steps
●   We can now run Plexus apps on top of Guice
●   ... and start separating apps into OSGi bundles
●   OSGi lets us dynamically add / remove bundles




●   ... but Guice bindings are static
Next Steps
●   How can we resolve this mismatch?




●   Find out in "Dynamic Guice Applications" ...
Links
JSR 330        http://code.google.com/p/atinject/


Guice          http://code.google.com/p/google-guice/


Spice-Inject   http://svn.sonatype.org/spice/trunk/spice-inject


OSGi           http://www.osgi.org/About/HowOSGi


Blog Updates   http://www.sonatype.com/people/author/mcculls/
Questions?
Transfo rm ing th e w ay so ftw are is m ad e .

More Related Content

PDF
As7 jbug j_boss_modules_yang yong
PDF
JBoss Wise: breaking barriers to WS testing
PDF
Nodejs guide
PDF
KEY
A nodejs application
PDF
くみこみからひとことReturns
PDF
02 java programming features of java i
PDF
JBoss Snowdrop
As7 jbug j_boss_modules_yang yong
JBoss Wise: breaking barriers to WS testing
Nodejs guide
A nodejs application
くみこみからひとことReturns
02 java programming features of java i
JBoss Snowdrop

Similar to Moving From Plexus To Guice (20)

PDF
Dynamic Guice Applications
PDF
NetflixOSS Open House Lightning talks
PDF
node.js 실무 - node js in practice by Jesang Yoon
PDF
J2EE vs JavaEE
PPTX
Comparison between zookeeper, etcd 3 and other distributed coordination systems
PDF
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PDF
Balisage - EXPath Packaging
ODP
Puppet managed loadays
PDF
GlassFish OSGi - Java2days 2010
PPTX
PDF
What's brewing in the eZ Systems extensions kitchen
PDF
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
PDF
Lupus Decoupled Drupal - Drupal Austria Meetup - 2023-04.pdf
PDF
Glassfish An Introduction
PDF
Introduction to Spring Framework
PDF
Netflix oss season 1 episode 3
PDF
I know Java, why should I consider Clojure?
PDF
OTN Developer Days - GlassFish
PPTX
Spring Framework Presantation Part 1-Core
PDF
What’s new in WSO2 Enterprise Integrator 6.6
Dynamic Guice Applications
NetflixOSS Open House Lightning talks
node.js 실무 - node js in practice by Jesang Yoon
J2EE vs JavaEE
Comparison between zookeeper, etcd 3 and other distributed coordination systems
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
Balisage - EXPath Packaging
Puppet managed loadays
GlassFish OSGi - Java2days 2010
What's brewing in the eZ Systems extensions kitchen
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Lupus Decoupled Drupal - Drupal Austria Meetup - 2023-04.pdf
Glassfish An Introduction
Introduction to Spring Framework
Netflix oss season 1 episode 3
I know Java, why should I consider Clojure?
OTN Developer Days - GlassFish
Spring Framework Presantation Part 1-Core
What’s new in WSO2 Enterprise Integrator 6.6
Ad

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Spectral efficient network and resource selection model in 5G networks
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
A Presentation on Artificial Intelligence
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Spectral efficient network and resource selection model in 5G networks
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
A Presentation on Artificial Intelligence
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Ad

Moving From Plexus To Guice

  • 2. Why move? ● Plexus is not widely used outside of Maven ● Lack of documentation, not always up-to-date ● Extra steps needed to generate Plexus XML ● Not type-safe, lacks support for generics
  • 3. Single plexus.xml ● META-INF/plexus/components.xml (Class-Path)
  • 4. Has annotations, but still need to generate XML
  • 5. Why ? ● Standard: reference implementation for JSR 330 ● Flexible: can map all sorts of metadata to bindings ● Type-safe: detailed messages when things go wrong ● Modular: multiple extensions available, OSGi-ready
  • 6. JSR 330 ● New standard for Java dependency injection // Constructor injection // Field injection // Setter injection
  • 7. Fluent Java binding API ● Records generic information lost during erasure ● Can be driven by Java / annotations / XML / ...etc...
  • 8. Migration Path ● Preserve investment in legacy Plexus components ● Allow gradual migration to JSR 330 annotations ● Must support mixture of Plexus and JSR 330
  • 9. Customizing ● Guice provides an SPI to hook into injections ● TypeListeners called for matching bound types ● Register MembersListeners for custom injection ● Register InjectionListeners for custom lifecycles ● SPI supports binding introspection / rewriting
  • 11. -y Beans ● Writing all those listener classes can get tedious ● guice-bean library cuts out most of the work ● You provide a BeanBinder implementation ● that can provide PropertyBinders for each type ● which can supply PropertyBindings for each property ● Bean conventions select field / setter properties
  • 13. Metadata ● Canonical form of Plexus bindings ● Captures @Component implementations ● ● Maps @Component bean properties to ● @Requirement settings ● @Configuration settings ● Interns Plexus hint strings to save space
  • 14. Scanning for Metadata ● ClassSpace abstraction supplies classes / resources ● Can be backed by Plexus Classworlds or OSGi ● Plexus XML mapped into Plexus annotations ● Plexus annotations are interpolated and stored
  • 15. Converting Configuration ● Builds on top of standard Guice TypeConverters ● Supports properties, nested collections, and beans ● Guice SPI lets you add your own TypeConverters
  • 16. Locating Components ● Guice bindings map Keys to Providers ● Each Key has a type and optional annotation ● Plexus components have roles and hints Key == Class<Role> + @Named(hint) ● Uses Guice SPI to find component bindings
  • 17. Binding Components ● Opposite of locating components ● @Component roles and hints turned into Keys ● Keys used to bind component implementations ● Singleton default, unless strategy is "per-lookup"
  • 18. Injecting Requirements ● @Requirement locate Plexus components ● Handles Maps, Lists, instances, and Wildcards ● Loggers automatically configured and injected ● @Configuration convert constant using type
  • 19. Managing Lifecycles ● Uses an InjectionListener to listen for bean instances ● Plexus lifecycle "personality" applied after injection ● Reverse lifecycle applied when container disposed ● Need to manage extra metadata (like descriptions)
  • 20. Time for a Demonstration!
  • 21. Classworlds ● Plexus Container API still depends on Classworlds ● But dependency is much less in guice-plexus-shim ● Just need to write classworlds-shim around OSGi ● ... to get Plexus apps running on OSGi containers
  • 22. Extending JSR 330 ● JSR 330 tells us how to mark dependencies ● and qualify them (just like with Plexus hints) ● But it does not say how to mark components
  • 23. Identifying JSR 330 components ● Wrap the Class-Path up as a ClassSpace and scan it ● Look for classes with qualifiers such as @Named ● Empty @Named means "use class name" instead ● Binding type found by analysing class hierarchy
  • 24. Next Steps ● We can now run Plexus apps on top of Guice ● ... and start separating apps into OSGi bundles ● OSGi lets us dynamically add / remove bundles ● ... but Guice bindings are static
  • 25. Next Steps ● How can we resolve this mismatch? ● Find out in "Dynamic Guice Applications" ...
  • 26. Links JSR 330 http://code.google.com/p/atinject/ Guice http://code.google.com/p/google-guice/ Spice-Inject http://svn.sonatype.org/spice/trunk/spice-inject OSGi http://www.osgi.org/About/HowOSGi Blog Updates http://www.sonatype.com/people/author/mcculls/
  • 28. Transfo rm ing th e w ay so ftw are is m ad e .