5

While doing the original training for EJBs from Sun I came across the rather strange concept of a enterprise application client which has the notion of dependecy injection and a main class:

@javax.ejb.EJB
private static auctionsystem.ejb.AuctionManagerRemote auctionManager;

public static void main (String[] args)
   {
   TestClient.logger.entering (TestClient.TAG, "main");

   final String message = "hello";
   TestClient.logger.log (Level.INFO, "Sending {0}", message);
   final String reply = auctionManager.communicationTest (message);
   TestClient.logger.log (Level.INFO, "Received {0}", reply);

   TestClient.logger.exiting (TestClient.TAG, "main");
   return;
   }

I just can't find any background info on this. Like:

  1. How is this supposed to work.
  2. How do you start such an application without NetBeans.
  3. How do you build this construct without NetBeans (i.E. with Maven).

Yes I do use NetBeans - but I am not satisfied if I can not do the same operation on the command-line and/or Maven as well.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Martin
  • 11,577
  • 16
  • 80
  • 110

2 Answers2

7

How is this supposed to work.

This must be a Java EE Application Client (another type of Java EE module that allows to wrap a Java SE application, deploy it to an application server and make use of deployed EJB, platform services and resources) and Java EE Application Client Main-Class does support injection of resources in static annotated fields or methods.

How do you start such an application without NetBeans.

Assuming the Application Client is packaged and deployed to the application server, you need to start the Application Client Container (ACC). The command is application server specific.

For example with GlassFish, you'd have to use the appclient command. With JBoss, see this wiki page for the (huge) command. For other app servers, refer to their respective documentation :)

How do you build this construct without NetBeans (i.E. with Maven).

An Application Client is a regular JAR containing:

  • The Java class to access the bean.
  • A META-INF/application-client.xml - (optional) Java EE application client deployment descriptor.
  • A META-INF/MANIFEST.MF file referencing the main class, which states the complete package prefix and class name of the Java client.
  • App server specific deployment descriptor - (optional)

Resources

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 1
    For a basic introduction that isn't tied to Sun's tooling (does anyone else *hate* his about the J2EE tutorials): http://docstore.mik.ua/orelly/java-ent/ebeans/ch11_04.htm – Tom Anderson Nov 02 '10 at 17:26
  • @Tom Yeah, this is a bit annoying. Actually, I could simply not find a good online resource for Java EE 5+ (i.e. using DI) outside the Java EE tutorial. – Pascal Thivent Nov 02 '10 at 17:33
  • There doesn't seem to be a way to run clients with JBoss 4, but here's how to do it with JBoss 5: http://community.jboss.org/wiki/HowtouseanapplicationclientinJBoss-5 – Tom Anderson Nov 02 '10 at 17:39
  • If package both app client and web module into `ear` package, how do I inject app client into web module to access it method? You know like how we inject EJB using `@EJB` from web module, how do I do that with app client? – Thang Pham Jun 17 '11 at 17:47
2

Answering my own question (again)

  1. How is this supposed to work?

    The main() class is deployed to the application server which injects the dependencies and calls main (). On glassfish deployment is done with a special command (appclient).

  2. How do you start such an application without NetBeans?

    As said on glassfish ou start the client with the use of appclient. For example:

    appclient -enableassertions -mainclass auctionapp.TestClient -jar target/AuctionApp-ejb.jar

  3. How do you build this construct without NetBeans (i.E. with Maven)?

    You create a normal executable jar. It will only work if your remote interfaces are inside a library as well (which is good praxis anyway) and this library is included inside your executable lib. You can use maven-assembly-plugin to create the executable. Just the same way you create a normal executable jar.

Thanks for all the help. Without SO I would not have found out the details.

Martin
  • 11,577
  • 16
  • 80
  • 110