views:

57

answers:

1

I've been using Seam 2 (also started looking into Java EE 6) in my web apps and a couple of days ago I found out that Seam's CDI can be leveraged in an SE application with Weld. According to Weld's Documentation page for Weld SE the setup is trivial. So I tried to setup an Eclipse project with a single class HelloWeld, weld-se.jar and the log4j jars.

@Singleton
public class HelloWeld
{
    public void printHello(@Observes ContainerInitialized event, @Parameters List<String> parameters)
    {
        System.out.println("Hello Weld!");
    }
}

I created a new Java Application Run Configuration and indicated org.jboss.weld.environment.se.StartMain as the main class. When I ran the project I found out, without any surprise what-so-ever, that HelloWeld was never called. All I got was a few log entries as an indication that Weld booted correctly:

11:54:39,397 INFO  [weld.Version] WELD-000900 1.0.1 (Final)
11:54:39,428 INFO  [weld.Bootstrap] WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
11:54:39,944 WARN  [model.InterceptionTypeRegistry] Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
11:54:39,944 WARN  [model.InterceptionTypeRegistry] Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled

So what am I missing?

+1  A: 

You need to make it a bean archive. Add an empty META-INF/beans.xml to your classpath.

Thorbjørn Ravn Andersen