There is an example in NetBeans site how to create Application Client using simple projects (without Maven). There are 4 projects needed (EJB, EAR, Lib, Program). This tutorial is simple and works perfectly.
I want to ask how to do the same with Maven? I can't manage to get all the dependencies correctly so when I try to call EJB method, it gives me NullPointerException
. Can anyone tell me, the key steps (preffered using NetBeans) that needs to be done? Because I am confused, about how many projects needs to be created? I know, that I need Application Project, EAR and EJB projects and thats it? What special configs needs to be written in these projects pom.xml files?
EDIT1:
I don't want to explicit JNDI I want to be able to use @EJB annotations.
Here are the steps:
Modify the application client's POM in order to use maven-assembly-plugin for obtaining a jar with dependencies. If you don't to this step, the deploy will fail because GF is not able to load the interface class. Add the following lines to the plugins
tab (change the main class as appropriate):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.entapp.entappclient.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Build the application client project with NB
appclient -jar EntAppClient-1.0-SNAPSHOT-jar-with-dependencies.jar
Useful link: Java EE's Buried Treasure: the Application Client Container by Jason Lee
Important Note
In order to deploy the client to oher JVMs you have to install the appclient on each client machine and set the target-server property. The appclient seems to have a very complicated structure, which you cannot produce simply by adding these lines (plus the EclipseLink persistence artifacts):
<dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
Adding these artifacts to the client compiles perfectly but the jar doesn't work. And this is understandable, since the file sun-acc.xml is missing (this file is necessary because contains the target-server property). Therefore I think that the only way is using the package-appclient
script as per the linked documentation.