Weld CDI inside eclipse plugin

I have a third-party library which uses weld, specifically weld-se-2.4.5. I want to make use of this library inside a plugin for a different third-party application that’s using the eclipse plugin framework. I cannot for the life of me get Weld to initialise successfully.

I can’t share either of the real applications, but I’ve made a minimal example plugin that I also can’t get to work for what I hope is the same reasons.

Activator.java:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package minimal_cdi;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "minimal-cdi"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
private static WeldContainer container;
/**
* The constructor
*/
public Activator()
{
}
@Override
public void start(BundleContext context) throws Exception
{
super.start(context);
plugin = this;
try
{
Weld weld = new Weld().property("org.jboss.weld.se.shutdownHook", false);
container = weld.initialize();
container.select(MainClass.class).get().start();
Runtime.getRuntime().addShutdownHook( new Thread( () -> {
container.select(MainClass.class).get().shutdown();
container.shutdown();
}));
}
catch (Exception e)
{
System.err.println(e.toString());
}
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
</code>
<code>package minimal_cdi; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.jboss.weld.environment.se.Weld; import org.jboss.weld.environment.se.WeldContainer; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "minimal-cdi"; //$NON-NLS-1$ // The shared instance private static Activator plugin; private static WeldContainer container; /** * The constructor */ public Activator() { } @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; try { Weld weld = new Weld().property("org.jboss.weld.se.shutdownHook", false); container = weld.initialize(); container.select(MainClass.class).get().start(); Runtime.getRuntime().addShutdownHook( new Thread( () -> { container.select(MainClass.class).get().shutdown(); container.shutdown(); })); } catch (Exception e) { System.err.println(e.toString()); } } @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * * @return the shared instance */ public static Activator getDefault() { return plugin; } } </code>
package minimal_cdi;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

    // The plug-in ID
    public static final String PLUGIN_ID = "minimal-cdi"; //$NON-NLS-1$

    // The shared instance
    private static Activator plugin;
    
    private static WeldContainer container;
    
    /**
     * The constructor
     */
    public Activator()
    {
    }

    @Override
    public void start(BundleContext context) throws Exception
    {
        super.start(context);
        plugin = this;
        try
        {
            Weld weld = new Weld().property("org.jboss.weld.se.shutdownHook", false);
    
            container = weld.initialize();
            container.select(MainClass.class).get().start();
    
            Runtime.getRuntime().addShutdownHook( new Thread( () -> {
                container.select(MainClass.class).get().shutdown();
                container.shutdown();
            }));
        }
        catch (Exception e)
        {
            System.err.println(e.toString());
        }       
    }

    @Override
    public void stop(BundleContext context) throws Exception {
        plugin = null;
        super.stop(context);
    }

    /**
     * Returns the shared instance
     *
     * @return the shared instance
     */
    public static Activator getDefault() {
        return plugin;
    }
}

Main class:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package minimal_cdi;
import javax.inject.Inject;
public class MainClass
{
@Inject
ThingDoer doer;
MainClass()
{
}
MainClass(ThingDoer doerIn)
{
doer = doerIn;
}
void start()
{
doer.doThing();
}
void shutdown()
{
doer.stop();
}
}
</code>
<code>package minimal_cdi; import javax.inject.Inject; public class MainClass { @Inject ThingDoer doer; MainClass() { } MainClass(ThingDoer doerIn) { doer = doerIn; } void start() { doer.doThing(); } void shutdown() { doer.stop(); } } </code>
package minimal_cdi;

import javax.inject.Inject;


public class MainClass
{
    @Inject
    ThingDoer doer;
    
    MainClass()
    {
    }
    
    MainClass(ThingDoer doerIn)
    {
        doer = doerIn;
    }
    
    void start()
    {
        doer.doThing();
    }
    
    void shutdown()
    {
        doer.stop();
    }
}

Interface to inject:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package minimal_cdi;
public interface ThingDoer
{
abstract public void doThing();
abstract public void stop();
}
</code>
<code>package minimal_cdi; public interface ThingDoer { abstract public void doThing(); abstract public void stop(); } </code>
package minimal_cdi;

public interface ThingDoer
{
    abstract public void doThing();
    abstract public void stop();
}

Implementation of the interface:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package minimal_cdi;
public class BeanieBoo implements ThingDoer
{
@Override
public void doThing()
{
System.out.println("Hello World");
}
public void stop()
{
System.out.println("Goodbye");
}
}
</code>
<code>package minimal_cdi; public class BeanieBoo implements ThingDoer { @Override public void doThing() { System.out.println("Hello World"); } public void stop() { System.out.println("Goodbye"); } } </code>
package minimal_cdi;

public class BeanieBoo implements ThingDoer
{
    @Override
    public void doThing()
    {
    System.out.println("Hello World");
    }

    public void stop()
    {
    System.out.println("Goodbye");
    }   
}

beans.xml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
</code>
<code><beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans> </code>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

I export the plugin and run it through the OSGI console and get the following output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Sept 24, 2024 10:57:47 AM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.4.5 (Final)
Sept 24, 2024 10:57:47 AM org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner getBeanArchiveReference
WARN: Unable to adapt URL: bundleresource://892.fwk1603300106:1/META-INF/beans.xml, using its external form instead
Sept 24, 2024 10:57:47 AM org.jboss.weld.environment.deployment.discovery.AbstractDiscoveryStrategy performDiscovery
WARN: WELD-ENV-000031: The bean archive reference bundleresource://892.fwk1603300106:1/META-INF/beans.xml cannot be handled by any BeanArchiveHandler: [org.jboss.weld.environment.deployment.discovery.FileSystemBeanArchiveHandler@ea1ce9b]
java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found
</code>
<code>Sept 24, 2024 10:57:47 AM org.jboss.weld.bootstrap.WeldStartup <clinit> INFO: WELD-000900: 2.4.5 (Final) Sept 24, 2024 10:57:47 AM org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner getBeanArchiveReference WARN: Unable to adapt URL: bundleresource://892.fwk1603300106:1/META-INF/beans.xml, using its external form instead Sept 24, 2024 10:57:47 AM org.jboss.weld.environment.deployment.discovery.AbstractDiscoveryStrategy performDiscovery WARN: WELD-ENV-000031: The bean archive reference bundleresource://892.fwk1603300106:1/META-INF/beans.xml cannot be handled by any BeanArchiveHandler: [org.jboss.weld.environment.deployment.discovery.FileSystemBeanArchiveHandler@ea1ce9b] java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found </code>
Sept 24, 2024 10:57:47 AM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.4.5 (Final)
Sept 24, 2024 10:57:47 AM org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner getBeanArchiveReference
WARN: Unable to adapt URL: bundleresource://892.fwk1603300106:1/META-INF/beans.xml, using its external form instead
Sept 24, 2024 10:57:47 AM org.jboss.weld.environment.deployment.discovery.AbstractDiscoveryStrategy performDiscovery
WARN: WELD-ENV-000031: The bean archive reference bundleresource://892.fwk1603300106:1/META-INF/beans.xml cannot be handled by any BeanArchiveHandler: [org.jboss.weld.environment.deployment.discovery.FileSystemBeanArchiveHandler@ea1ce9b]
java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found

New contributor

Steven Irrgang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật