Sunday, May 5, 2013

Java EE main method - Hello World application

    Java SE has clearly defined entry point of the program execution - 'public static void main(String[] args)' method. However, when it comes to Java EE such an entry point is blurred. Can we create main method in Java EE?
The answer is: YES. The simplest possible solution is @Singleton bean with @Startup and @PostConstruct annotations:
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;

public class MainMethodBean {
 public void main() {
  System.out.println("Hello world from java EE!");

We have just created our Java EE (EJB3.1) 'Hello world' application! Now you can configure your environment and deploy your EJB.


  1. You did't reduced complexity of issues discussed on your blog, did You? ;)